phil
phil

Reputation: 313

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. The code below works fine on android. I am working on cordova 6.5.0 and the inappbrowser plugin is version 1.6.1. I am currently working on 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. I am more than happy to provide more info such as my 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". I've also tried window.open() without any success.

Edit 2: The redirect function is called on click of this button

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

Upvotes: 3

Views: 3182

Answers (1)

phil
phil

Reputation: 313

Okay, so after trying several things this is what worked for me. I tested firing all four possible inappbrowser events on different targets. The only target for which these events would fire back was "_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".

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.

Upvotes: 2

Related Questions