ios js调oc,oc调js

1,oc调js

[self.webView stringByEvaluatingJavaScriptFromString:

[NSString stringWithFormat:@"javascript:chatConnect('%@','%@','%@');",

2,js调oc

//首先创建JSContext 对象(此处通过当前webView的键获取到jscontext)

JSContext *context=[webView valueForKeyPath:@"documentView.webView.mainFrame.javaScriptContext"];

context[@"showDanmu"] = ^() {

NSArray *args = [JSContext currentArguments];

for (id obj in args) {

NSString *str = [obj toString];

}

}

};

你可能感兴趣的:(ios js调oc,oc调js)