一、传参给ios
// iosapp交互
function setupWebViewJavascriptBridge(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)
}
setupWebViewJavascriptBridge(function(bridge) {
bridge.callHandler(
'name', // ios里定义的方法名
{'code': data.info.code}, // 要传递的参数数组
function(response) {}
)
})
二、传参给安卓
// 安卓回调
function customerParam(bridge, code) {
var data = {
code: code, // 要传的参数
};
bridge.send(data, function (responseData) {
// alert('回调');
});
}
window.appCustomer.customerParam(data.info.code);
注:appCustomer是安卓的类库名,customerParam是方法名