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 ?? ""
}
}
}
网友评论