标签:scheme mac os x webapp ffffff idg 怎么 tor sch func
/*这段代码是固定的,必须要放到js中*/
function setupWebViewJavascriptBridge(callback) {
var u = navigator.userAgent;
var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);
if (!isiOS) {
if (window.WebViewJavascriptBridge) {
callback(WebViewJavascriptBridge)
} else {
document.addEventListener(‘WebViewJavascriptBridgeReady‘, function (event) {
if(window.onWebViewJavascriptBridgeReady) window.onWebViewJavascriptBridgeReady(window.__bridge = WebViewJavascriptBridge);
callback(WebViewJavascriptBridge)
}, false)
}
} else {
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)
}
}
export default {
callhandler (name, data, callback) {
setupWebViewJavascriptBridge(function (bridge) {
bridge.callHandler(name, data, callback)
})
},
registerhandler (name, callback) {
setupWebViewJavascriptBridge(function (bridge) {
bridge.registerHandler(name, function (data, responseCallback) {
callback(data, responseCallback)
})
})
}
}
// 调用
this.$bridge.callhandler(‘shopCode‘,{‘test‘:‘test‘},(data) => {
this.shopCode = data.shopCode;
})
标签:scheme mac os x webapp ffffff idg 怎么 tor sch func
原文地址:https://www.cnblogs.com/langqq/p/9813296.html