Skip to content

A better way to call openHandleURL !!! #337

@rolinger

Description

@rolinger

the openHandleURL fires way before the app fully initializes EVEN when set in the deviceReady section of app.js or main.js. This is particularly worse when an app launches for the very first time. Example scenario: User installs the app BUT doesn't open it - the app has never initialized on the users phone before. Then the user clicks on an external URL Scheme (or QR Code) that redirects them into the app. This will cause window.handleOpenURL to fire well before the first time app initialization is complete and the redirected URL won't work.

For years, everyone has been using the following:

    window.handleOpenURL = function(url) {
        setTimeout(_ => {
          .... do stuff here
       },0) ;

But even beyond the first time app initialization scenario above, working off of timers can bite you in the ass because sometimes some things take just hair longer than your timeout timer - and then your redirected URL will fail within your app.

To manage this I changed to the following method:

    window.handleOpenURL = function(url) {
      var doURL = $interval(function() { 
        if (getDB("app_initialized") !== null) {    // <----- specific app local storage value is set
          $interval.cancel(doURL) ;
          openURL(url) ;
        }
      },100) ;
      function openURL(url) {
        setTimeout(_ => {
           ... do stuff here
       },0) ;
    }

Change your interval trigger to whatever you want....but this ensures you can control WHEN handleOpenURL will fire. In my case, I set a bunch of localStorage variables upon first time install....app_initialized is the last one to be set. When its set, then my environment is ready to go.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions