Christian Gossain
Christian Gossain

Reputation: 5972

How can I tell if the user opened my app for the first time?

I was wondering how would I determine on the launch of my application whether or not it was opened for the first time.

I was thinking that I need a bool instance variable. But after that I'm just not sure.

Upvotes: 2

Views: 313

Answers (2)

Daniel Amitay
Daniel Amitay

Reputation: 6667

NSUserDefaults *standardUserDefaults = [NSUserDefaults standardUserDefaults];   
BOOL haveused = [standardUserDefaults boolForKey:@"haveused"];

if(haveused)
{       
    //NOT THEIR FIRST TIME
    //Handle scenario
}
else
{
    //THEIR FIRST TIME
    //Handle scenario
    [standardUserDefaults setBool:TRUE forKey:@"haveused"];
    [standardUserDefaults synchronize];
}

The only exception is if the user deletes and reinstalls your application. If they delete and reinstall, it wipes your applications memory clean, and it will see the user as a first timer. But this will remain functional throughout updates.

Upvotes: 12

Dr. McKay
Dr. McKay

Reputation: 91

NSUserDefaults is of course the way to go for this, but I just want to point out that you could have just stat or fopen'd a file tell if this was the virgin use. Or even HTTP GET a URL the first time, then to file, or blah blah you get the idea.

Upvotes: 1

Related Questions