1. Andrews interaction
h5 method call Andrews
window.webview.xxx()
Andrews calls h5 methods, methods need to be registered in the Global
window['showUnreadMsg'] = () => { this.$nextTick(() => { this.showUnreadMsg(); }) }
2. ios interaction
function setupWebViewJavascriptBridge(callback) { if (window.WebViewJavascriptBridge) { return callback(window.WebViewJavascriptBridge) } if (window.WVJBCallbacks) { return window.WVJBCallbacks.push(callback) } window.WVJBCallbacks = [callback] let WVJBIframe = document.createElement('iframe') WVJBIframe.style.display = 'none' WVJBIframe.src = 'https://__bridge_loaded__' document.documentElement.appendChild(WVJBIframe) setTimeout(() => { document.documentElement.removeChild(WVJBIframe) }, 0) }
h5 method call ios
setupWebViewJavascriptBridge(function(bridge){ bridge.callHandler('getPhoneNumber',(data) => { that.loginApp(data) }) })
ios call h5 method, we also need a global register
setupWebViewJavascriptBridge(function(bridge){ bridge.registerHandler('showUnreadMsg',(data,responseCallback)=>{ if(responseCallback){ that.showUnreadMsg(); } })
})