iOS 11 - WKWebView进展KVO从未达到100%

时间:2017-09-06 18:00:39

标签: ios swift wkwebview

我正在为iOS 11的升级版本测试应用程序。在使用应用程序内浏览器(WKWebView)进行导航时,我使用KVO来更新进度。不幸的是,它从未达到100%。这是我的代码(在iOS 10中完美运行):

override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {

    if keyPath == "estimatedProgress" {
        print("progres \(webView.estimatedProgress)")
        if webView.estimatedProgress == 1.0 {
            print("progress reached 100%")
            progressView.setProgress(1.0, animated: true)
            UIView.animate(withDuration: 0.3, delay: 0.3, options: .curveEaseOut, animations: {
                self.progressView.alpha = 0.0
            }, completion: { (finished) in
                self.progressView.setProgress(0.0, animated: false)
                self.progressView.isHidden = true
            })
        }
        else {
            progressView.alpha = 1.0
            progressView.isHidden = false
            progressView.setProgress(Float(webView.estimatedProgress), animated: true)
        }
    } else if keyPath == "title" {
        navigationItem.title = webView.title
    }
    else {
        super.observeValue(forKeyPath: keyPath, of: object, change: change, context: context)
    }
}

以下是Xcode控制台打印输出的示例:

> progres 0.1 
> progres 0.5 
> progres 0.55430649853092 
> progres 0.771510689002141 
> progres 0.77167516785194

1 个答案:

答案 0 :(得分:0)

经过调查,看起来问题来自我正在使用的特定内部网址的复杂网络设置。使用代理修复了问题。