js 与oc 交互

1.githup 上下载好WebViewJavascriptBridge,拉到项目里

2. js 端代码里配置好,

3. @property(nonatomic,strong)WebViewJavascriptBridge *bridge;

4.[self.webView loadRequest: request];

5.if (!_bridge) {

6.[WebViewJavascriptBridge enableLogging];

7._bridge = [WebViewJavascriptBridge bridgeForWebView:self.webView webViewDelegate:self handler:^(id data, WVJBResponseCallback responseCallback) {

NSLog(@"ObjC received message from JS: %@", data);

}];

__weak typeof(self)weakSelf = self;

/ /参数和 js 端定义好

8.[_bridge registerHandler:@"CommonCallback" handler:^(id data, WVJBResponseCallback responseCallback) {

}

你可能感兴趣的:(js 与oc 交互)