swift动态获取WKWebView title

webView.uiDelegate = self
webView.addObserver(self, forKeyPath: "title", options: NSKeyValueObservingOptions.new, context: nil)

然后在回调方法中

    override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?){
        if keyPath == "title" {
            if object as? WKWebView == webView {
                title = webView.title ?? ""
            }
        }
    }

你可能感兴趣的:(swift动态获取WKWebView title)