Android's addJavascriptInterface equivalent in

2019-03-25 04:40发布

As you may know, Android's WebView has a method named addJavascriptInterface() which imports an Android JAVA object to Javascript context.

the question is, Is there any equivalent of it on iOS?

2条回答
看我几分像从前
2楼-- · 2019-03-25 05:25

I know this question is really old, but it seems that there is a better way to do it now with a WKWebView. See this answer: https://stackoverflow.com/a/37373745/1417922

查看更多
爷的心禁止访问
3楼-- · 2019-03-25 05:26

UIWebView on iOS doesn't have methods to add interface to DOM.
But you still can talk to your code from javascript assigning something to window.location and handling that request in webView:shouldStartLoadWithRequest:navigationType: delegate method.

查看更多
登录 后发表回答