代码开源在:OC中初始化:
|
1
2
|
TGJSBridge *jsBridge = [TGJSBridge jsBridgeWithDelegate: webViewDelegate];<u><font color="\"red\"">webView</font></u>.delegate = jsBridge;
|
发消息到JS:
|
1
|
postNotificationName:userInfo:toWebView: |
监听消息:
|
1
|
- (void)jsBridge:(TGJSBridge *)bridge didReceivedNotificationName:(NSString *)name userInfo:(NSDictionary *)userInfo fromWebView:(UIWebView *)<u><font color="\"red\"">webview</font></u>
|
js发送消息:
|
1
|
jsBridge.postNotification(msgName,userInfo); |
js监听消息:
|
1
2
3
|
jsBridge.bind(msgName, function(userInfo){ ...
}); |
js取消监听消息:
|
1
|
jsBridge.unbind('test',callbackHandler);
|