我有一个viewController,我在其中创建了一个WKWebView,这是一个委托方法:
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
let model = SwiftJSModel()
self.jsContext = webView.value(forKeyPath: "documentView.webView.mainFrame.javaScriptContext") as! JSContext
model.jsContext = self.jsContext
self.jsContext.setObject(model, forKeyedSubscript: "modelObject" as NSCopying & NSObjectProtocol)
}
然而,在加载此webView后,我的应用程序将崩溃,控制台显示:
reason: '[<WKWebView 0x7fc41d9c7200> valueForUndefinedKey:]: this class is not key value coding-compliant for the key documentView.'
似乎webView.value(forKeyPath: "documentView.webView.mainFrame.javaScriptContext")
在swift3中不起作用,有人知道为什么吗?