Initializing Variables First Time Use - Proper way?

Hey Guys,

I want to setup a few variables on the very first time the app is run, along with a little user agreement screen they have to click/tap agreement too.

I thought about storing the agreement confirmation as a Boolean in ngStorage but not sure if that will be wiped when the app updates from the app store/google play. As that would be a bad thing since it would then re-initialize variables the user has already set each time.

What is the best solution and proper practice for this problem? Don’t want to build it the wrong way now and be stuck with something broken.

I guess the real question is: What is the best way to setup a first time load screen on my app?

Thanks for any help you can offer!

On ios, I would use Keychain to store such information (simply as json string):

When app gets replaced by a new version, the keychain is still there.

Android, I dont know…

just found that:

Im not using ngcordova yet, have to lurk inside that :smile:

1 Like

thanks dant, much appreciated. for that permanence suggestion.

any thought on the best way to check if its the first run?

this appears to be one way… , alternatively i could just set s boolean… thoughts on best practices?

Hi BioPerl,

the ionic-wizard module are simply some directives to create a wizard but it does not deal with data persistence. You could however add the logic to the wizard controller to initialize variables using ngStorage for example. I would set a flag whenever the wizard is run for the first time, save that to localStorage, so the next time the app is launched simply check for that flag and skip the wizard.
Let me know if you need any help. Would be cool to add such scenario to the module.

1 Like

havent quite figured out how to make it run only once yet. it because a recurrsive problem, I can set a flag when its run once, and then check that flag on all future launches of the app, but the very first time that flag isn’t defined, and if i define it first, then that would reset it everytime… i know there is was to do this beyond normal varribles, some kind of Angular hook or ionic call… but i havent figured it out yet

Hi BioPerl,

I finally managed to find time to update the module. I added an example ionic project to the package where you can see how the wizard plays well with localStorage. It only runs the first time and then checks for a flag that is defined inside the controller. It is a very basic example and it can be improved.
The example-storage folder is a ionic project so you can simply run: ionic serve inside it in order to test the wizard.

Hope it helps. Let me know!

arielf , I finally got around to adding this to my app. WOW just wow. amazing job, really. your code is documented so nicely that it was literally the easiest thing i have ever added to my Ionic code.

flag works perfectly.

thanks again =)

1 Like

hey arielf , just noticed a bug, not sure if you are aware of it. but on android 4.3 and below ( im testing on 5 , 4.4, 4.3 and 4.1) all the screens appear on top of each other and not seperate on first load.

perhaps a css bug?

im going to look into it, but you already know the solution give me a shout