swift调用网页中的点击事情
2018-05-14 本文已影响6人
piggybear
swift代码
func webViewDidFinishLoad(_ webView: UIWebView) {
let context = webView.value(forKeyPath: "documentView.webView.mainFrame.javaScriptContext") as? JSContext
let callBack : @convention(block) (AnyObject?) -> Void = { [weak self] (paramFromJS) -> Void in
DispatchQueue.main.async {
}
}
context?.setObject(unsafeBitCast(callBack, to: AnyObject.self), forKeyedSubscript: "iosMethod" as NSCopying & NSObjectProtocol)
}
html代码
function btnClick()
{
iosMethod();
}
在html button点击事件下面加一行iosMethod
,然后swift去调用