iOS 中WKWebView之Js调用OC如何返回值?
2019-02-14 本文已影响26人
天下林子
用过WKWebView的会知道,代理中没提供带有返回值的代理方法,那不就gg了~~ 怎么破?
参见代码:
UIWebView:
JSContext *jsContext = [self.webView valueForKeyPath:@"documentView.webView.mainFrame.javaScriptContext"];
jsContext[@"sayhi"] = ^(NSString *name) {
NSLog(@"say hi to %@",name);
return "say hi to xxxx";
};
对于WKWebView,参见下图
