movii
6/29/2017 - 5:42 AM

笔记:iOS 与 JavaScript 的交互(三):WKWebView 2. Show loading progress

笔记:iOS 与 JavaScript 的交互(三):WKWebView 2. Show loading progress

// 首先添加监听
webView.addObserver(
    self, 
    forKeyPath: #keyPath(WKWebView.estimatedProgress), 
    options: .new, 
    context: nil
)

// 监听回调
override func observeValue(
    forKeyPath keyPath: String?,
    of object: Any?,
    change: [NSKeyValueChangeKey : Any]?,
    context: UnsafeMutableRawPointer?) {
    
    if keyPath == "estimatedProgress" {
        // do something 
    }
                             
}