Chris
Chris

Reputation: 7310

Objective C: Recognize if user is opening app for first time

I made an alert that randomly appears to remind the user to rate the app and then set a key BOOL to YES so that it doesn't pop up when a user hits rate. I need to initially set this to NO. Is there a function or variable that knows if its the first time a user is opening an app?

Upvotes: 1

Views: 1230

Answers (3)

0x8badf00d
0x8badf00d

Reputation: 6401

Set the BOOL firstTimeAppLaunch; firstTimeAppLaunch = TRUE; then [[NSUserDefaults standardUserDefaults] setBool:firstTimeAppLaunch forKey:@"firstTimeFlag"];

then read it

BOOL tempFirstAppLaunch = [[NSUserDefaults standardUserDefaults] boolForKey:@"firstTimeFlag"];
    if(tempFirstTimeAppLaunch==TRUE)
    {
          //doSomething
        }

Upvotes: 2

Matthew Frederick
Matthew Frederick

Reputation: 22305

If you save any kind of preferences, any configuration file, or anything else when the app is used, you can check for the existence of that data and assume first-use or a device restore and new install if that data isn't there at app start.

That probably sounds obvious. The point being that you can save some data to check for, a good example being a counter that indicates the number of times the app has launched (or re-awakened), ensuring that you don't ask for a rating until after at least the 3rd launch.

Upvotes: 0

Dave DeLong
Dave DeLong

Reputation: 243156

If you're using NSUserDefaults to store this BOOL, then when you ask the defaults for boolForKey:, it will automatically return NO if the BOOL does not exist in the defaults.

Upvotes: 8

Related Questions