调用 UIWebViewDelegate 方法“当我想要时”

Calling UIWebViewDelegate method "when I want"

本文关键字:当我想要时 我想要 UIWebViewDelegate 方法 调用      更新时间:2023-09-26

我正在使用webView:shouldStartLoadWithRequest:navigationType方法从JavaScript调用我的Objective-C代码,它工作正常。问题是,此方法仅在重新加载 Web 视图时被调用。我希望能够"随时"发送消息。这可能吗?

具体来说,我想尽可能多地使用document.location = "myapp:" + "customerAdded:" + "YES";。我的代码只有在我使用 Google API V3 绘制地图时才会执行。

是否可以重新加载"不可见"帧以调用委托方法?

试试这个,对我来说很好用

function invokeObjectiveC() {
    var iframe = document.createElement("IFRAME");
    iframe.setAttribute(your stuff here);
    document.documentElement.appendChild(iframe);
    iframe.parentNode.removeChild(iframe);
    iframe = null;
}

webView:shouldStartLoadWithRequest:navigationType: 只应在 Web 视图重新加载时调用,这就是此委托的目的。可以使用NSNotificationCenter调用重新加载 Web 视图的方法。

相关文章: