Summary: Use of plug-in for the Webviewjavascriptbridge,app end need to introduce this package, HTML page only a section of JS code
interacting with iOS
<! Affirm interaction (here Code fixed) >
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 = ' https://__bridge_loaded__ ';
Document.documentElement.appendChild (Wvjbiframe);
SetTimeout (function () {Document.documentElement.removeChild (wvjbiframe)}, 0)
}
<!--process The interaction method name to correspond to the definition in iOS
Setupwebviewjavascriptbridge (function (bridge) {
Bridge.registerhandler ("Showalert", function (data) {//ios Call JS method
Alert (data+ ", 54646")
});
Bridge.callhandler (' Objcechotojs ', {foo: ' Bar '}, function (response) {//js Call iOS method
Alert (' Receive callback: ' +response)
})
})
Interacting with Android
<! Affirm interaction (here Code fixed) >
function Connectwebviewjavascriptbridge (callback) {
if (window. Webviewjavascriptbridge) {
Callback (Webviewjavascriptbridge)
} else {
Document.addeventlistener (' Webviewjavascriptbridgeready ', function () {
Callback (Webviewjavascriptbridge)
},false);
}
}
<!--process The interaction method name to correspond to the definition within Android
Connectwebviewjavascriptbridge (function (bridge) {
Bridge.registerhandler ("Functioninjs", function (data, responsecallback) {//android Call JS method
alert (data);
});
Bridge.callhandler (' Objcechotojs ', {' param ': Data}, Function (responsedata) {//js Call Android method
alert (responsedata);
});
})
Summary: The interactive Declaration code fixed, interface and ios/android corresponding to the good (attached: the front-end Registerhandler method interface corresponding to their callhandler, Callhandler method interfaces correspond to their registerhandler)
App Embedded H5 Web page (Webviewjavascriptbridge)