以下代码在Android中正常运行。但是,它在IOS中不起作用。
我们认为 browser.executeScript 在这里不起作用。这里我们从API获取重定向URL作为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&gt;
<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://*/*" />
cordova插件ls
com.darktalker.cordova.screenshot 0.1.5“截图”
cordova-plugin-actionsheet 2.3.3“ActionSheet”
cordova-plugin-compat 1.1.0“Compat”
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“Geolocation”
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 基础“
cordova-plugin-mfp-jsonstore 8.0.2017081712“IBM MobileFirst Platform 基金会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“短信”
cordova-plugin-splashscreen 4.0.3“Splashscreen”
cordova-plugin-statusbar 2.2.2“StatusBar”
cordova-plugin-whitelist 1.3.1“白名单”
cordova-plugin-x-socialsharing 5.1.8“社交分享”
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“启动 导航“
请帮助我们解决此问题......
由于
答案 0 :(得分:0)
我解决了这个问题。
browser.executeScript({ code: "document.write('" + this.paymentGatewayDetails + "');" });
适用于IOS和Android
我在这里删除了 .then( (成功)=&gt; {
现在新的代码在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")
}
}
)}
我不知道为什么它不起作用。如果有人知道,请回答。
由于