检测WKWebView何时完成加载 [英] Detect when WKWebView has finished loading EVERY time

查看:5237
本文介绍了检测WKWebView何时完成加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在iPad上的iOS8上运行WKWebView应用程序(标准iPad UserAgent:Mozilla / 5.0(iPad; CPU OS 8_1_1,如Mac OS X)AppleWebKit / 600.1.4(KHTML,如Gecko)版本/ 8.0 Mobile / 12B436 Safari浏览器/ 600.1.4\" )。我已经尝试了所有我能想到的代表和监听器,每次尝试检测页面何时完成加载。问题在于:

I have a WKWebView app running on iOS8 on iPad (standard iPad UserAgent : "Mozilla/5.0 (iPad; CPU OS 8_1_1 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Version/8.0 Mobile/12B436 Safari/600.1.4"). I have tried all delegates and listeners I can think of to try and detect when a page has finished loading, every time. Here is the problem:


  1. 打开WKWebView并转到Google。以下称为:

  1. Open your WKWebView and go to Google. The following are called:

_decidePolicyForNavigationAction
_didStartProvisionalNavigation
_ didFinishNavigation


  • 在Google中输入YouTube:
    仅调用_decidePolicyForNavigationAction。没有didStartProvisionalNavigation或didFinishNavigation

  • Type "YouTube" into Google: ONLY _decidePolicyForNavigationAction is called. No didStartProvisionalNavigation or didFinishNavigation

    点击Google内的YouTube。以下称为:

    Click on YouTube within Google. The following are called:

    _didStartProvisionalNavigation
    _decidePolicyForNavigationAction
    _ didFinishNavigation
    


  • 从现在开始,在YouTube内没有任何内容被称为。点击YouTube视频,没有didStartProvisionalNavigation或didFinishNavigation。此外,不再调用webview.loading观察者。甚至decisionPolicyForNavigationAction也只是偶尔被调用。但是...... webView.backForwardList.currentItem 会在每次点击后更新,因此必须检测页面何时以某种方式加载完毕?

  • From now on, within YouTube nothing is called. Click on a YouTube video and no didStartProvisionalNavigation or didFinishNavigation. Also, webview.loading observer is no longer called. Even decidePolicyForNavigationAction is only called every now and then. HOWEVER… The webView.backForwardList.currentItem is updated after every click, so this must be detecting when the page has finished loading somehow?

    此行为也发生在很多其他网站上(例如Vimeo)。我知道这种类型的网站每次都没有更新主框架,但缺乏检测何时加载已经开始/完成WKWebView当前状态的限制的能力?

    This behavior happens on a lot of other sites too (Vimeo for example). I know this type of site is not updating the main frame every time, but is this lack of a capability to detect when loading has started/finished a ‘limitation’ of WKWebView in its current state?

    我想要实现的目标是:是否有其他方法可以检测导航何时完成,每次在Java / Vimeo等Java移动网站中

    What I want to achieve is: Is there another way to detect when navigation has COMPLETED, EVERY TIME within Java mobile websites like YouTube/Vimeo:


    • 使用NSURLProtocol或类似的?

    • 或者可能是一种检测
      webView.backForwardList.currentItem何时更新的方法?

    感谢您的帮助。

    推荐答案

    我不确定当页面加载时您想要做什么,但是希望观察这些属性可以帮助你:

    I'm not sure what exactly you want to do when page have loaded, but hopefully observing these properties can help you:

    webView.addObserver(self, forKeyPath: "estimatedProgress", options: .New, context: nil)
    webView.addObserver(self, forKeyPath: "loading", options: .New, context: nil)
    webView.addObserver(self, forKeyPath: "title", options: .New, context: nil)
    webView.addObserver(self, forKeyPath: "canGoBack", options: .New, context: nil)
    webView.addObserver(self, forKeyPath: "canGoForward", options: .New, context: nil)
    

    这篇关于检测WKWebView何时完成加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆