Error while sending message from WKWebView to the {N} application


#1

Hi all!

I again about of the nativescript-vkwebview plugin. I trying from a webview send a message to the application, but after line window.webkit.messageHandlers.vkMessenger.postMessage('message'); app crashes. Gives this error which can be understood by Objective-C or Swift developers:

-[TNSDictionaryAdapter userContentController:didReceiveScriptMessage:]: unrecognized selector sent to instance 0x60800003fe40
May 24 00:51:41 Akmals-iMac com.apple.CoreSimulator.SimDevice.4F74F604-F98D-4C73-8D55-C58D8970C468.launchd_sim[4135] (UIKitApplication:org.nativescript.demo[0xf454][5054]): Service exited due to Segmentation fault: 11

That line is called from here:

<!doctype html>
<html>
<head>
    <title>WKWebView</title>
    <style>
        body {
            background-color: #00aafc;
            font-family: monospace;
            font-size: 48px;
            text-align: center;
            color: white;
        }
    </style>
    <script>
        var body, windowKeys;

        function init() {
            body = document.getElementsByTagName('body')[0];
            windowKeys = [];
        }

        function red() {
            try {
                window.webkit.messageHandlers.vkMessenger.postMessage('message');
                windowKeys.push('Your message has been sent!');
            } catch (err) {
                windowKeys.push('Error: ' + err.toString());
            }

            setTimeout(function () {
                body.style.color = 'black';
                body.style.backgroundColor = 'white';
                body.innerText = windowKeys.join('\n');
            }, 500);
        }
    </script>
</head>
<body onload="init()">
    <p>WKWebView is loaded!</p>
</body>
</html>

Thanks.