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.
the
openHandleURLfires way before the app fully initializes EVEN when set in thedeviceReadysection 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 causewindow.handleOpenURLto 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:
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:
Change your interval trigger to whatever you want....but this ensures you can control WHEN
handleOpenURLwill fire. In my case, I set a bunch of localStorage variables upon first time install....app_initializedis the last one to be set. When its set, then my environment is ready to go.