suale-dev / JavaScriptInterface

Calling native code from Javascript in the iOS application likes addJavascriptInterface in the Android.
36 stars 8 forks source link

UIWebview -> WKWebview? #6

Open Gjworks opened 7 years ago

Gjworks commented 7 years ago

HELLO :) iOS 11 version and swift4 WKWebView addJavascriptInterface How do I update?

chinmaykdas commented 6 years ago

I also have the same question. I also want his solution for WKWebView

iggyto commented 5 years ago

Hi, I am trying to use the library with WKWebView, and I encounter a problem with the jsinterface configuration callback not being called. Any idea on how to make this library work with WKWebView?

mureatencio commented 5 years ago

I'm trying to create a WKWebView based version, did you find a way to make it work?

iggyto commented 5 years ago

@mureatencio No, I wasn't able to make it work. I had to use userContentController

let contentController = WKUserContentController() 
contentController.add(self, name: "configureNotifications")

// Webview setup
let webConfiguration = WKWebViewConfiguration()
webConfiguration.userContentController = contentController

And then implement the "delegate":

func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) {
        if message.name == "configureNotifications" {
           // do your magic
        }
    }