JavaScript与OC的交互

来源:互联网 发布:kali linux风扇 编辑:程序博客网 时间:2024/05/19 17:51

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

0 0