Checking application launch for the first time using Cordova 3.0

Is there a way in Cordoba 3.0 to check if this is done the first time the application is launched without using a database for this purpose.

+6
source share
3 answers

You can use localStorage to check a variable. Try something like this:

in the docummentready event:

if(window.localStorage.getItem('has_run') == '') { //do some stuff if has not loaded before window.localStorage.setItem('has_run', 'true'); } 
+10
source

Dawson Loudon solution does not work for me, but try the following:

 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"); } 
+1
source

You should use sessionStorage instead of localStorage.

The correct code would 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"); } 

This is because localStorage is persistent, while sessionStorage is not.

-1
source

Source: https://habr.com/ru/post/959239/


All Articles