Appendix: Code Snippets
Iconic/Cordova Phonegap Sample
//Call Trips from Ionic using plugin : https://www.npmjs.com/package/cordova-plugin- inappbrowser
var weburl
=” https://widget.staging.trips.ng?/?MerchantCode={MerchantCode}&MerchantHash=
{token}&CustomerNmae={CustomerNmae}&CustomeId={CustomerId}” var target
= "_blank";
var options = "location=no,hidden=yes,footer=yes,closebuttoncaption=Done"; var
inAppBrowserRef = cordova.InAppBrowser.open(weburl,
target,
options
);
//IONIC RECEIVING MESSAGE
inAppBrowserRef.addEventListener("message", messageCallBack); function
messageCallBack(params: { data: any }) {
//display message somewhere
setMessageReceived("message received: " + JSON.stringify(params.data));
}
React Native Sample
//Call Trips from Ionic using plugin : https://www.npmjs.com/package/react-native- webview
var weburl
=” https://widget.staging.trips.ng?/ MerchantCode={MerchantCode}&MerchantHash=
{token}&CustomerNmae={CustomerNmae}&CustomeId={CustomerId}”
return (
<WebView
source={{
uri: weburl
}}
onNavigationStateChange={event => {
if (event.url === ' https://widget.staging.trips.ng?/') { navigation.navigate('Home');
}
}}
onMessage={message => {
// alert(data.nativeEvent.data); console.log('VALUE:',
message.nativeEvent.data);
}}
// style={{ marginTop: 20 }}
/>
);
Flutter Sample
//Call Trips from Ionic using plugin : https://pub.dev/packages/flutter_inappwebview
//SENDING TO FLUTTER
if (window.flutter_inappwebview) {
window.flutter_inappwebview.callHandler(
"myHandlerName",
stringifiedObj
);
}
//FLUTTER RECEIVING MESSAGE
onWebViewCreated:(controller) {
// register a JavaScript handler with name "myHandlerName" controller.addJavaScriptHandler(handlerName:
'myHandlerName', callback: (args) {
// print arguments coming from the JavaScript side! print(args);
// return data to the JavaScript side! return {
'bar': 'bar_value', 'baz': 'baz_value'
};
});
},
Other flutter plugin : 1. https://pub.dev/packages/url_launcher 2. https://pub.dev/packages/webview_flutter
Swift Sample
Webview plugin : https://developer.apple.com/documentation/webkit/wkwebview
Kotlin/Java Sample
Last updated