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去调用
网友评论