一、js调用oc
(1)事先与接口约定好协议,如buy代表购买
(2)在shouldStartLoadWithRequest
方法中如果url中包含buy则执行oc代码,否则继续加载原url
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
if ([request.URL.absoluteString containsString:@"buy"]) {
return NO;
}
return YES;
}
(二)原生调用js
调用stringByEvaluatingJavaScriptFromString方法(buyed是js的方法)
[webview stringByEvaluatingJavaScriptFromString:@"buyed"];
网友评论