简体   繁体   English

Cordova InAppBrowser EventListeners 不适用于 ios

[英]Cordova InAppBrowser EventListeners not working on ios

When run on the iphone 7 device or emulator, inappbrowser successfully opens, but the eventlisteners are never called.在 iphone 7 设备或模拟器上运行时,inappbrowser 成功打开,但从未调用事件侦听器。 The code below works fine on android.下面的代码在android上运行良好。 I am working on cordova 6.5.0 and the inappbrowser plugin is version 1.6.1.我正在使用cordova 6.5.0 并且inappbrowser 插件是1.6.1 版。 I am currently working on mac osx 10.12.2.我目前正在使用 mac osx 10.12.2。

function redirect () {
  if (isloggedin){
    navigator.notification.alert("You are already logged in");
  } else {
    var url = "https://connect.stripe.com/oauth/authorize?response_type=code&client_id=CLIENT_ID&scope=read_write";
    var target = "_system";
    var options = "location=yes, hidden=no, clearcache=yes";
    browserRef.addEventListener('loadstart', function(event) {
      if ((event.url).indexOf("https://example.com") !== -1) {
        var redirectedURI = event.url;
        registerUser(redirectedURI);
        browserRef.close();
      }
    });
  }
}

Here is an image of a navigator notification with info about browserRef.这是导航器通知的图像,其中包含有关 browserRef 的信息。 I am more than happy to provide more info such as my config.xml.我非常乐意提供更多信息,例如我的 config.xml。 Any help is much appreciated, thanks.非常感谢任何帮助,谢谢。

Edit: Whenever I try adding browserRef.close() at the end of my redirect function, I get an error from xcode "IAB.close() called but it was already closed".编辑:每当我尝试在重定向函数的末尾添加 browserRef.close() 时,我都会收到来自 xcode 的错误“IAB.close() 调用,但它已经关闭”。 I've also tried window.open() without any success.我也试过 window.open() 没有任何成功。

Edit 2: The redirect function is called on click of this button编辑 2:单击此按钮时调用重定向功能

<a href="#" onClick="redirect();">Online Payments</a>

Okay, so after trying several things this is what worked for me. 好的,所以在尝试了几件事后,这对我有用。 I tested firing all four possible inappbrowser events on different targets. 我测试了在不同目标上发射所有四个可能的inappbrowser事件。 The only target for which these events would fire back was "_blank". 这些事件将被击退的唯一目标是“_blank”。

browserRef.addEventListener('loadstart', function(event) { navigator.notification.alert(event, event.url); });
browserRef.addEventListener('loadstop', function(event) { navigator.notification.alert(event); });
browserRef.addEventListener('loaderror', function(event) { navigator.notification.alert(event, event.code, event.message); });
browserRef.addEventListener('exit', function(event) { navigator.notification.alert("exit"); });

Something else I noticed: For some reason "loadstart" would only run on "_self". 我注意到的其他事情:由于某种原因,“loadstart”只会在“_self”上运行。

Although I have worked around the issue, if anyone can provide some insight into why this happens, I'd be glad to provide some more details about my code/build. 虽然我已经解决了这个问题,但如果有人能够提供一些有关为什么会发生这种情况的见解,我很乐意提供有关我的代码/构建的更多详细信息。

Problem was my iOS platform wasn't latest. 问题是我的iOS平台不是最新的。

So when you developing apps using cordova make sure your platform versions and plugins are up-to date with OS upgraded. 因此,当您使用cordova开发应用程序时,请确保您的平台版本和插件是最新的操作系统升级版本。

So all I had to do is 所以我所要做的就是

Removing iOS platform. 删除iOS平台。

cordova platform rm ios Cordova平台rm ios

Adding iOS platform - Latest Version 添加iOS平台 - 最新版本

cordova platform add ios cordova平台添加ios

Removing the plugin cordova-plugin-inappbrowser 删除插件cordova-plugin-inappbrowser

cordova plugin remove cordova-plugin-inappbrowser cordova插件删除cordova-plugin-inappbrowser

Adding the plugin cordova-plugin-inappbrowser - Latest Version 添加插件cordova-plugin-inappbrowser - 最新版本

cordova plugin add cordova-plugin-inappbrowser cordova插件添加cordova-plugin-inappbrowser

https://guntucomputerhacks.blogspot.com/2019/07/cordova-inappbrowser-eventlisteners-not.html https://guntucomputerhacks.blogspot.com/2019/07/cordova-inappbrowser-eventlisteners-not.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM