'Trying to invoke an event in an Angularjs + RequireJS running in a WKWebView

We are trying to invoke event in an AngularJS + RequireJS app from a WKWebView.

So far we have used window.webkit.messageHandlers to invoke events from the web app to the native app using window.webkit.messageHandlers.

Would it be possible to have AngularJS add a function to window.webkit.messageHandlers that the native app can invoke?

So far we have tried.

window.webkit.messageHandlers.webClientTrigger = function (theParameter) {
                    console.debug("in webClientTrigger " + theParameter);
                };

And then all it from the native app as

webView.evaluateJavaScript("window.webkit.messageHandlers.webClientTrigger('test');", completionHandler: nil)


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source