【发布时间】:2017-11-08 13:22:30
【问题描述】:
我想在WKWebView 中获取点击链接的网址。链接采用自定义格式,将触发应用程序中的某些操作。例如http://my-site/help#deeplink-intercom。我像这样使用KVO:
override func loadView() {
let webConfiguration = WKWebViewConfiguration()
webView = WKWebView(frame: .zero, configuration: webConfiguration)
webView.navigationDelegate = self
webView.addObserver(self, forKeyPath: "URL", options: .new, context: nil)
view = webView
}
override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
if let newValue = change?[.newKey] {
print("url changed: \(newValue)")
}
print("Did tap!!")
}
这在第一次点击链接时效果很好。但是,如果我连续两次点击相同的链接,它不会报告链接点击(显然是因为实际值没有改变)。是否有解决此问题的解决方法,以便我可以检测到每次点击并获取链接?任何关于此的指针都会很棒!谢谢!
【问题讨论】: