You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Error: An unimplemented method has been called #13
extension ViewController: JavaScriptInterface {
func someFunc() -> String {
return "alert('close.')" //so alert would be presented in webView when this method is called.
}
}
or
extension ViewController: JavaScriptInterface {
func someFunc() -> String {
return "Something" //return some string to JS and let it handle it.
}
}
In JS, I am calling it like this, for example when button is tapped: return iosListener.someFunc(); //iosListener is a name of userContentController
This is how I implement webView:
webView = WKWebView(frame: view.bounds, configuration: setupWebViewConfiguration())
webView.navigationDelegate = self
webView.uiDelegate = self
let javaScriptController = WKJavaScriptController(name: "iosListener", target: self, bridgeProtocol: JavaScriptInterface.self)
webView.javaScriptController = javaScriptController
webView.prepareForJavaScriptController()
view.addSubview(webView)
//then load the url
I am getting this error: [WKJavaScriptController] An unimplemented method has been called. (selector: someFunc)
Also worth mentioning, my script where I call this method is being called by evaluateJavascript(), when url is loaded. I am not using WKUserScript. My JS is on the web, and I am using evaluateJavascript() to return Swift method.
Activity