[英]AddEventListener not working for InAppBrowser - IONIC 2
[英]IONIC 2 InAppBrowser is not working in IOS
下面的代码在Android中工作正常。 但是,它在IOS中不起作用。
我们认为browser.executeScript在这里不起作用。 在这里,我们从API获得的重定向网址为html内容(this.paymentGatewayDetails) ,我们需要打开它。 它在android中工作正常。
在IOS 11.0手机中尝试此操作。
IONIC 2.2版本
插件@ ionic-native / in-app-browser“:” ^ 4.3.2“
这是我们试图执行的功能。
callGateway() {
return new Promise(
(resolve, reject) => {
let injected = false;
if (!this.paymentGatewayDetails) {
reject("PG_DET_INVALID")
}
const browser = this.iab.create("about:blank", "_blank", "location=no");
browser.show()
//inject html code to blank page. one time
browser.on("loadstop")
.subscribe(
(sucess) => {
if (!injected) {
browser.executeScript({ code: "document.write('" + this.paymentGatewayDetails + "');" }).then(
(sucess) => {
console.log("sucess");
browser.executeScript({ code: "document.mypg.submit();" }).then(
(sucess) => {
console.log("sucess redirection");
}, (err) => {
console.log("error redirection");
}
);
}, (err) => {
console.log("err")
}
);
injected = true;
}
console.log("success url is", sucess.url);
if (sucess.url.includes("mobile.mypg.com")) {
//payment gateway call sucess.
browser.close()
resolve("PG_CALL_SUCC")
}
}
)}
我们已经在PLIST文件中给出了
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
然后在INDEX.html>
<meta http-equiv="Content-Security-Policy" content="default-src gap://ready file://* *; script-src 'self' 'unsafe-inline' 'unsafe-eval' *; style-src 'self' 'unsafe-inline';”>
我们还安装了白名单插件
科尔多瓦插件白名单
在config.xml中还添加了这些行
<content src="index.html" />
<access origin="*" subdomains="true" />
<allow-navigation href="http://*/*" />
<allow-navigation href="https://*/*" />
<allow-navigation href="data:*" />
<allow-intent href="http://*/*" />
<allow-intent href="https://*/*" />
科尔多瓦插件ls
com.darktalker.cordova.screenshot 0.1.5“屏幕截图”
cordova-plugin-actionsheet 2.3.3“ ActionSheet”
cordova-plugin-compat 1.1.0“兼容”
cordova-plugin-console 1.0.5“控制台”
cordova-plugin-device 1.1.4“设备”
cordova-plugin-dialogs 1.3.3“通知”
cordova-plugin-fcm 2.1.2“ FCMPlugin”
cordova-plugin-geolocation 2.4.3“地理位置”
cordova-plugin-globalization 1.0.7“全球化”
cordova-plugin-hotline 1.2.1“ Phonegap的热线插件”
cordova-plugin-inappbrowser 1.7.1“ InAppBrowser”
cordova-plugin-mfp 8.0.2017072706“ IBM MobileFirst Platform Foundation”
cordova-plugin-mfp-jsonstore 8.0.2017081712“ IBM MobileFirst Platform Foundation JSONStore”
cordova-plugin-nativestorage 2.2.2“ NativeStorage”
cordova-plugin-okhttp 2.0.0“ OkHttp”
cordova-plugin-screen-orientation 2.0.1“屏幕方向”
cordova-plugin-sms 1.0.5“ SMS”
cordova-plugin-splashscreen 4.0.3“启动画面”
cordova-plugin-statusbar 2.2.2“ StatusBar”
cordova-plugin-whitelist 1.3.1“白名单”
cordova-plugin-x-socialsharing 5.1.8“ SocialSharing”
cordova.plugins.diagnostic 3.6.6“诊断”
es6-promise-plugin 4.1.0“承诺”
ionic-plugin-keyboard 2.2.1“键盘”
uk.co.workingedge.phonegap.plugin.launchnavigator 4.0.4“启动导航器”
请帮助我们解决此问题...
谢谢
我解决了这个问题。
browser.executeScript({ code: "document.write('" + this.paymentGatewayDetails + "');" });
适用于IOS和Android
在这里,我删除了.then((成功)=> {
现在,新代码可同时在IOS和Android上使用
callGateway() {
return new Promise(
(resolve, reject) => {
let injected = false;
if (!this.paymentGatewayDetails) {
reject("PG_DET_INVALID")
}
const browser = this.iab.create("about:blank", "_blank", "location=no");
browser.show()
//inject html code to blank page. one time
browser.on("loadstop")
.subscribe(
(sucess) => {
if (!injected) {
browser.executeScript({ code: "document.write('" + this.paymentGatewayDetails + "');" });
console.log("sucess");
browser.executeScript({ code: "document.mypg.submit();" }).then(
(sucess) => {
console.log("sucess redirection");
}, (err) => {
console.log("error redirection");
}
);
injected = true;
}
console.log("success url is", sucess.url);
if (sucess.url.includes("mobile.mypg.com")) {
//payment gateway call sucess.
browser.close()
resolve("PG_CALL_SUCC")
}
}
)}
我不知道为什么它在那里不起作用。 如果有人知道,请回答。
谢谢
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.