I'm building a page like SPA and want to monitor the URL, but the delegate isn't called and I can't detect it
Monitor the url
property of WKWebView with KVO.
class ViewController: UIViewController{
var webView: WKWebView
private var _observers = [NSKeyValueObservation]()
//Omission
override func viewDidLoad(){
_observers.append(webview.observe(\.url, options: .new) { _, _ in
print("URL: \(self.webView.url)")
})
}
}
https://stackoverflow.com/questions/47829963/how-can-i-detect-when-url-of-amp-page-changed-with-wkwebview/48273950
https://qiita.com/ObuchiYuki/items/d00ce5f44725672184da
Recommended Posts