JavaScript与OC的交互

JavaScript与OC有两个交互的桥梁


webView执行完js代码后可以返回一个字符串

NSString *result = [webView stringByEvaluatingJavaScriptFromString:js];

通过以下代理方法监听webView的页面跳转,并解析request,实现通过js调用OC。

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType;

请参考:https://github.com/kouliang/A-template-for-the-interaction-of-OC-and-JS

原文地址:https://www.cnblogs.com/coderkl/p/4320307.html