OC:
//接受JS数据
[_bridge registerHandler:@"callBackScanPayStr" handler:^(id data, WVJBResponseCallback responseCallback) {
responseCallback(@"Response from iOSCallback");
NSMutableDictionary *dic = [[NSMutableDictionary alloc] initWithDictionary:(NSDictionary *)data];
DLog(@"scanPay = %@",dic);
_amt = dic[@"amt"];
_merNo = dic[@"merNo"];
_orderId = dic[@"merOrderId"];
_merName = dic[@"merName"];
_notifyUrl = dic[@"notifyUrl"];
_recordId = [dic[@"recordId"] isEqualToString:@"null"] ? nil : dic[@"recordId"];
[self etcTransitionVC:nil];
}];
对应的jS代码:
var data = {
merchantOrderId: merchantOrderId,
payParentId: pPayParentId,
merchantOrderAmt: merchantOrderAmt,
orderDate: pAddTime
};
if(plantform === 'IOS') {
pSetupWebViewJavascriptBridge(function(bridge) {
bridge.callHandler('callBackScanPayStr', data, function(response) {
});
});
} else if(plantform === 'ANDROID') {
window.etc.HtmlcallETC(JSON.stringify(order));
}
本来以为这样就好了 ,经过异地返回的打包扫码测试,怀疑jS是不是确少类似OC的文件或者库文件。
说是缺少这个方法 JS和OC交互固定的写法,要不然没反应;
pSetupWebViewJavascriptBridge = function(callback) {
if(window.WebViewJavascriptBridge) {
return callback(WebViewJavascriptBridge);
}
if(window.WVJBCallbacks) {
return window.WVJBCallbacks.push(callback);
}
window.WVJBCallbacks = [callback];
var WVJBIframe = document.createElement('iframe');
WVJBIframe.style.display = 'none';
WVJBIframe.src = 'wvjbscheme://__BRIDGE_LOADED__';
document.documentElement.appendChild(WVJBIframe);
setTimeout(function() {
document.documentElement.removeChild(WVJBIframe)
}, 0)
}
最后 同事给了个js文件 public.js 自带这个方法,给异地的哥们导入进去打包测试,一次过。