Android的addJavascriptInterface相当于iOS中Android、addJavascriptInterface、iOS

2023-09-06 03:33:23 作者:温柔又能打

正如你可能知道,Android的的WebView有一个名为方法 addJavascriptInterface()进口一个Android Java对象的Javascript环境。

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

问题是,是否有它的iOS任何等价?

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

推荐答案

UIWebView的iOS上没有方法接口添加到DOM。 但你还是可以跟你的code从JavaScript分配的东西 window.location的和处理该请求web视图:shouldStartLoadWithRequest:navigationType:委托方法。

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.