Sometimes we have to check if the user is running our app for the first time so that we can, for example, display some information on how to navigate through the application.
It would be nice to have a few lines of code, that will do the job for us.
Here is the code:
static NSString* const hasRunAppOnceKey = @"hasRunAppOnceKey";
NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
if ([defaults boolForKey:hasRunAppOnceKey] == NO)
[defaults setBool:YES forKey:hasRunAppOnceKey];
// do some action here
That's all we need to do! We use NSUserDefaults to store our config variable that will not be set only for the first time.
We can place it anywhere we want, but in most cases it will be viewDidLoad method in the first controller.