5

I am trying to detect the first time launch of a newly installed application and display a license agreement for the application. The user must accept the lincense or leave the application..

Does anyone know how I can do this using Phonegap? I have searched through the topics but I cant seem to find this anywhere.

Thank You

ZodTron
  • 63
  • 1
  • 4

2 Answers2

19

You can use local storage to keep track of app launch counts.

var applaunchCount = window.localStorage.getItem('launchCount');

//Check if it already exists or not
if(applaunchCount){
   //This is a second time launch, and count = applaunchCount
}else{
  //Local storage is not set, hence first time launch. set the local storage item
  window.localStorage.setItem('launchCount',1);

  //Do the other stuff related to first time launch
}
Manish Kumar
  • 1,062
  • 8
  • 19
  • Thanks for the info... I am not very technical, so can this be done with javascript and a custom message shown on first launch?.. Even if this is a
    element that only shows on the first launch it would be perfect
    – ZodTron Feb 21 '13 at 19:15
  • Yeah.. you can show the custom message in the else part(which is the case for first launch) – Manish Kumar Feb 21 '13 at 20:21
1

Now iOS may clear localStorage, so you cannot count on it being persistent.

For truly persistent storage, one option would be the file system plugin

https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-file

Please note that if your APP is uninstalled, your persistent file would most likely be removed also. Which is probably fine for this application.

J. McNerney
  • 576
  • 4
  • 15