IONIC 2 InAppBrowser не работает в IOS

1

Этот код работает отлично в Android. но в IOS он не работает.

Мы считаем, что browser.executeScript здесь не работает. здесь мы получаем URL-адрес перенаправления из API в виде содержимого html (this.paymentGatewayDetails), и нам нужно его открыть. Он отлично работает в Android.

  1. пробуя это в телефоне IOS 11.0.

  2. Версия IONIC 2.2

  3. Plugin @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';">

Мы также установили плагин Whitelist

Cordova-плагин-белый список

В 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 "Скриншот"

плагин-плагин-плагин 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"

Кордова-плагин-геолокация 2.4.3 "Геолокация"

Кордоба-плагин-глобализация 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"

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 "Splashscreen"

Строка cordova-plugin-status 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-prom-plugin 4.1.0 "Обещание"

ионная плагин-клавиатура 2.2.1 "Клавиатура"

uk.co.workingedge.phonegap.plugin.launchnavigator 4.0.4 "Launch Navigator"

Пожалуйста, помогите нам решить эту проблему...

Спасибо

  • 0
    Можете ли вы отредактировать свой пост, чтобы включить ваши плагины Cordova. ionic cordova plugins ls
Теги:
cordova
ionic2
inappbrowser

1 ответ

0

Я решил проблему.

browser.executeScript({ code: "document.write('" + this.paymentGatewayDetails + "');" }); работает для IOS и Android

Здесь я удалил .then((sucess) => {

Теперь новый код, который работает как в 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")
        }
      }
      )}

Я не знаю, почему это не работает. Если кто-то знает это, ответьте.

Спасибо

Ещё вопросы

Сообщество Overcoder
Наверх
Меню