Custom-URL-scheme
Custom-URL-scheme copied to clipboard
A better way to call openHandleURL !!!
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.
On which platform did you experience this?
I get this warning during launch of my app on iOS (tried iphone 5s and iphone 4): THREAD WARNING: ['Flashlight'] took 36.587158' ms. Plugin should use a background thread.
Same issue here : it happens only on Samsung Galaxy S5 in cordova release mode and the toggle method is called when the user taps a button. The result is : the camera of the device is not working anymore, I have to manually kill the app to access the camera again. Here is the code :
var isOn = false;
....
if (window.plugins && window.plugins.flashlight) {
window.plugins.flashlight.available(function (isAvailable) {
if (isAvailable) {
window.plugins.flashlight.toggle(function () {
isOn = !isOn;
});
}
});
}
Android takes too long the turn its camera off and on again.
I implemented a third parameter to switchOff(null, null, true)
to avoid turning the camera off completely and changing only the flashlight parameter.
https://github.com/lucasdupin/Flashlight-PhoneGap-Plugin
Interesting addition. You'll only use that if you need to blink it repeatedly, right?
What happens if you use the soft switch off and open the camera app? Does it have trouble accessing the camera?
Right, only if you need to blink it repeatedly.
You must turn it off with switchOff();
to release the camera before quitting your app/activity.
But either way, this is something you are probably already doing.
FYI On Android the plugin now executes everything on a background thread (v 3.1.0)