title: iPhone - handleOpenURL Custom-URL-scheme plugin - not redirecting back to the application
body: <p>I have an app written with AngularJS 1.5.3, Cordova, and Ionic v1.</p>
  <p>I'm using these 2 plugins to implement some SSO (Single-Sign-On) functionality.</p>
  <p><a href="https://github.com/EddyVerbruggen/Custom-URL-scheme" rel="nofollow noreferrer">https://github.com/EddyVerbruggen/Custom-URL-scheme</a></p>
  <p><a href="https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-inappbrowser/" rel="nofollow noreferrer">https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-inappbrowser/</a></p>
  <pre><code>ionic info
  
  Ionic:
  
     ionic (Ionic CLI) : 4.10.3 (C:\Users\User\node_modules\ionic)
     Ionic Framework   : ionic1 1.3.5
     @ionic/v1-toolkit : 1.0.22
  
  Cordova:
  
     cordova (Cordova CLI) : 8.1.2 (cordova-lib@8.1.1)
     Cordova Platforms     : android 8.1.0, ios 6.1.0, browser 5.0.4, windows 4.4.3
     Cordova Plugins       : cordova-plugin-ionic-webview 4.1.3, (and 17 other plugins)
  
  System:
  
     Android SDK Tools : 26.1.1 (C:\Users\User\Documents\Android\sdk)
     NodeJS            : v10.21.0 (C:\Program Files\nodejs\node.exe)
     npm               : 6.14.4
     OS                : Windows 10
  </code></pre>
  <p>config.xml</p>
  <pre><code>   &lt;plugin name=&quot;cordova-plugin-inappbrowser&quot; spec=&quot;^4.0.0&quot;&gt;
          &lt;variable name=&quot;usewkwebview&quot; value=&quot;true&quot; /&gt;
      &lt;/plugin&gt;
      
      &lt;plugin name=&quot;cordova-plugin-customurlscheme&quot; spec=&quot;https://github.com/EddyVerbruggen/Custom-URL-scheme.git&quot;&gt;
          &lt;variable name=&quot;URL_SCHEME&quot; value=&quot;selfserviceapp&quot; /&gt;
          &lt;variable name=&quot;ANDROID_SCHEME&quot; value=&quot; &quot; /&gt;
          &lt;variable name=&quot;ANDROID_HOST&quot; value=&quot; &quot; /&gt;
          &lt;variable name=&quot;ANDROID_PATHPREFIX&quot; value=&quot;/&quot; /&gt;
      &lt;/plugin&gt;
  
  As I'm using cordova-ios 6.1.0 I'm using WkWebView only.
  
  &lt;platform name=&quot;ios&quot;&gt;
      &lt;preference name=&quot;WKWebViewOnly&quot; value=&quot;true&quot; /&gt;
  </code></pre>
  <p>package.json</p>
  <pre><code> &quot;dependencies&quot;: {
      &quot;cordova-android&quot;: &quot;^8.1.0&quot;,
      &quot;cordova-ios&quot;: &quot;^6.1.0&quot;,
      &quot;cordova-android-support-gradle-release&quot;: &quot;^3.0.1&quot;,
      &quot;cordova-plugin-camera&quot;: &quot;^4.1.0&quot;,
      &quot;cordova-plugin-compat&quot;: &quot;^1.2.0&quot;,
      &quot;cordova-plugin-customurlscheme&quot;: &quot;git+https://github.com/EddyVerbruggen/Custom-URL-scheme.git&quot;,
      &quot;cordova-plugin-device&quot;: &quot;^2.0.3&quot;,
      &quot;cordova-plugin-file&quot;: &quot;^6.0.2&quot;,
      &quot;cordova-plugin-geolocation&quot;: &quot;^4.0.2&quot;,
      &quot;cordova-plugin-inappbrowser&quot;: &quot;^4.0.0&quot;,
      &quot;cordova-plugin-network-information&quot;: &quot;^2.0.2&quot;,
      &quot;cordova-plugin-safariviewcontroller&quot;: &quot;^1.6.0&quot;,
      &quot;cordova-plugin-save-image&quot;: &quot;^0.3.0&quot;,
      &quot;cordova-plugin-settings-hook&quot;: &quot;^0.2.7&quot;,
      &quot;cordova-plugin-splashscreen&quot;: &quot;^5.0.4&quot;,
      &quot;cordova-plugin-statusbar&quot;: &quot;^2.4.3&quot;,
      &quot;cordova-plugin-whitelist&quot;: &quot;^1.3.4&quot;,
      &quot;cordova.plugins.diagnostic&quot;: &quot;^4.0.12&quot;,
      &quot;ionic-plugin-keyboard&quot;: &quot;^2.2.1&quot;,
      &quot;natives&quot;: &quot;^1.1.6&quot;
    },
  
  
      &quot;plugins&quot;: {
        &quot;cordova-plugin-splashscreen&quot;: {},
        &quot;cordova-plugin-statusbar&quot;: {},
        &quot;cordova-plugin-compat&quot;: {},
        &quot;cordova-plugin-device&quot;: {},
        &quot;cordova-plugin-settings-hook&quot;: {},
        &quot;cordova-plugin-save-image&quot;: {},
        &quot;cordova-plugin-file&quot;: {},
        &quot;cordova-plugin-network-information&quot;: {},
        &quot;cordova-plugin-whitelist&quot;: {},
        &quot;ionic-plugin-keyboard&quot;: {},
        &quot;cordova-plugin-safariviewcontroller&quot;: {},
        &quot;cordova-plugin-camera&quot;: {},
        &quot;cordova-plugin-geolocation&quot;: {},
        &quot;cordova.plugins.diagnostic&quot;: {
          &quot;ANDROID_SUPPORT_VERSION&quot;: &quot;28.+&quot;
        },
        &quot;cordova-android-support-gradle-release&quot;: {
          &quot;ANDROID_SUPPORT_VERSION&quot;: &quot;27.+&quot;
        },
        &quot;cordova-plugin-customurlscheme&quot;: {
          &quot;URL_SCHEME&quot;: &quot;selfserviceapp&quot;,
          &quot;ANDROID_SCHEME&quot;: &quot; &quot;,
          &quot;ANDROID_HOST&quot;: &quot; &quot;,
          &quot;ANDROID_PATHPREFIX&quot;: &quot;/&quot;
        },
        &quot;cordova-plugin-inappbrowser&quot;: {
          &quot;usewkwebview&quot;: &quot;true&quot;
        }
      }
  </code></pre>
  <p>The app will open the Identity provider in a browser, the user will log in there, and then the user will be re-directed back to the application.</p>
  <p>It's working perfectly on Android but for iOS it does not redirect back to the application.</p>
  <p>It stays on the browser page and the user has to manually click the 'done' button to redirect back to the application.</p>
  <p>*-Info.plist</p>
  <p><a href="https://i.stack.imgur.com/35MRt.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/35MRt.png" alt="enter image description here" /></a></p>
  <p><a href="https://i.stack.imgur.com/8SPrm.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/8SPrm.jpg" alt="enter image description here" /></a></p>
  <p>code snippet:</p>
  <p>on window object</p>
  <pre><code>var handleOpenURL = null;
  
  window['handleOpenURL'] = function (url) {
  
      if (handleOpenURL) {
          handleOpenURL(url);
      }
  
  };
  
  
          self.openUrl = function (url) {
  
              return new Promise(function (resolve, reject) {
  
                  try {
  
                      SafariViewController.isAvailable(function (available) {
                          if (available) {
  
                              self.hideSpinner();
  
                              handleOpenURL = function (url) {
  
                                  if (url.startsWith(ClientConfig.config.redirect_uri)) {
                                      self.processAuthCodeResponse(url)
                                          .then(function (token) {
                                              resolve(token);
                                          })
                                          .catch(function(error) {
                                              reject(error);
                                          })
                                          .finally(function() {
                                              window['SafariViewController'].hide();
                                          });
                                  }
                              }
  
                              SafariViewController.show({
                                  url: url
                              })
  
                          } else {
                              alert(' Browser Not Available! ');
                          }
  
                      });
  
                  }
                  catch (error) {
                      reject(error);
                  }
  
              });
  
          };
  </code></pre>