![](/img/trans.png)
[英]Calling javascript function from in objective c using webview methods
[英]Calling Objective C function from UIWebView using Ajax
我在网上找到了一个教程,其中说可以使用以下Javascript代码从WebView调用ObjectiveC代码
var iframe = document.createElement("IFRAME");
iframe.setAttribute("src", "js-frame:myObjectiveCFunction");
document.documentElement.appendChild(iframe);
iframe.parentNode.removeChild(iframe);
iframe = null;
然后从ObjectiveC,我必须实现UIWebViewDelegate来接收shouldStartLoadWithRequest。 我尝试了这段代码,它起作用了; 但是,我想知道是否可以使用AJAX调用而不是IFrame来实现相同的功能。
如果您使用JS更改window.location,则可以完成此操作。 它将调用您正在使用的委托函数。
您也可以使用同一委托方法,使用页面上的链接来执行obj-c函数。
如果您打算使用AJAX拨打特殊电话,请进一步说明。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.