/** * js 調用ios的方法 * @param callback */ function connectWebViewJavascriptBridge(callback) { if (window.WebViewJavascriptBridge) { callback(WebViewJavascriptBridge) } else { document.addEventListener('WebViewJavascriptBridgeReady', function() { callback(WebViewJavascriptBridge) }, false) } } //js 調用ios的方法 , connectWebViewJavascriptBridge(function(bridge) { // bridge.callHandler('payedNotify', {'foo': 'bar'}, function(response) {}); var data = 'resumeSuccess'; bridge.send(data, function(responseData) { log('JS got response', responseData) }) })
若是對以上代碼不太明白,能夠github上面的搜索connectWebView ,能夠找到源碼,有readME能夠參考ios