【问题标题】:IONIC 2 InAppBrowser is not working in IOSIONIC 2 InAppBrowser 在 IOS 中不起作用
【发布时间】:2018-04-01 19:48:57
【问题描述】:

以下代码在 Android 中运行良好。但是,它在 IOS 中不起作用。

我们认为 browser.executeScript 在这里不起作用。在这里,我们从 API 获取 重定向 url 作为 html 内容 (this.paymentGatewayDetails),我们需要打开它。它在android中运行良好。

  1. 在 IOS 11.0 手机上试试这个。

  2. IONIC 2.2 版本

  3. 插件@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';”>

我们还安装了白名单插件

cordova-plugin-whitelist

在 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“兼容”

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 平台 基金会”

cordova-plugin-mfp-jsonstore 8.0.2017081712“IBM MobileFirst 平台 基础 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“闪屏”

cordova-plugin-statusbar 2.2.2 “状态栏”

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“启动 导航器”

请帮助我们解决此问题...

谢谢

【问题讨论】:

  • 您能否编辑您的帖子以包含您的科尔多瓦插件。 ionic cordova plugins ls

标签: javascript ios cordova ionic2 inappbrowser


【解决方案1】:

我解决了这个问题。

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")
        }
      }
      )}

我不知道为什么它在那里不起作用。如果有人知道,请回答。

谢谢

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-24
    • 2017-07-12
    • 1970-01-01
    • 2019-10-08
    • 2017-08-02
    相关资源
    最近更新 更多