Is there a way in Cordova 3.0 to check if that's the first time the application runs without using the DB for that purpose.
Checking first time app launch using Cordova 3.0
Asked Answered
you could use a localStorage variable –
Pammie
write an answer and I will accept –
Gum
You could use localStorage to check for a variable. Try something like this:
in docummentready event:
if(window.localStorage.getItem('has_run') == '') {
//do some stuff if has not loaded before
window.localStorage.setItem('has_run', 'true');
}
What about the data expiration from user agent? –
Christmann
Dawson Loudon's solution didn't work for me but try this:
var count = window.localStorage.getItem('hasRun');
if(count){
console.log("second time app launch");
}else{
// set variable in localstore
window.localStorage.setItem('hasRun',1);
console.log("first time app launch");
}
You must use sessionStorage instead of localStorage.
The correct code will be:
var count = window.sessionStorage.getItem('hasRun');
if (count) {
console.log("second time app launch");
} else {
// set variable in localstore
window.sessionStorage.setItem('hasRun', 1);
console.log("first time app launch");
}
It's because localStorage is persistent while sessionStorage ain't..
That's why you want to use localStorage, it has to be persistent otherwise the data could be removed, and it looks like your app is launching for the first time. –
Zoniazoning
© 2022 - 2024 — McMap. All rights reserved.