![](/img/trans.png)
[英]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.