gpt4 book ai didi

ios - 如何正确监听 UIWebView 上的导航变化?

转载 作者:技术小花猫 更新时间:2023-10-29 11:05:10 24 4
gpt4 key购买 nike

我注意到 [UIWebViewDelegate webView:shouldStartLoadWithRequest:navigationType:]仅使用传统的 <a href="..."> 调用链接而不是单页网络应用程序 JavaScript 导航。

例如,如果我在 UIWebView 中访问 m.facebook.com并开始点击顶部导航(请参见下面的屏幕截图)它永远不会触发该委托(delegate)方法。

我想要 Hook 方法的原因是因为我想在 UIWebView 上方添加后退和前进按钮,但我需要知道何时启用/禁用这些按钮。我应该使用其他一些委托(delegate)方法来正确收听导航更改吗?

更新:我还应该注意到,移动版 Safari 会正确更新 Facebook 移动网站上的后退/前进按钮状态,因此我希望 Apple 也能为开发人员提供一种方法来执行此操作。

enter image description here

最佳答案

UIWebViewDelegate 和 WKNavigationDelegate(我刚刚在 facebook 上测试过)似乎都不支持。 this answer 中列出了一些选项:

  1. javascript injection to capture the page changes (read up on history.pushState).
  2. KVO to watch for changes to the webview (like the scrollview resizing)
  3. watching for the title change, as above.
  4. checking for updates every time the user taps the view.

更新

我也试过this answer在 facebook 上,这涉及在每个新页面加载期间注入(inject) javascript 以捕获 XMLHTTPRequests。它有点可以满足您的要求,但有点hack。某些 Facebook 选项卡无法通过非常简单的实现正常工作,但您可以解决这些问题。

关于ios - 如何正确监听 UIWebView 上的导航变化?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41512659/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com