JavaScriptInterface icon indicating copy to clipboard operation
JavaScriptInterface copied to clipboard

UIWebview -> WKWebview?

Open Gjworks opened this issue 8 years ago • 4 comments

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

Gjworks avatar Nov 28 '17 06:11 Gjworks

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

chinmaykdas avatar Dec 07 '17 11:12 chinmaykdas

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?

iggyto avatar Dec 05 '18 14:12 iggyto

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

mureatencio avatar Jan 23 '19 19:01 mureatencio

@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
        }
    }

iggyto avatar Jan 25 '19 00:01 iggyto