iOS和JS交互

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   自带这个方法,给异地的哥们导入进去打包测试,一次过。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值