Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check for first launch of my application

How would I check if it is the first launch of of my application using NSUserDefaults and running some code for the first time my app opens?

like image 215
atomikpanda Avatar asked Jul 07 '12 00:07

atomikpanda


People also ask

How to detect first time app launch on an Iphone?

You need to save something when you launch and then check to see if it exists. If not, it's the first time. "Something" can be a file, a database entry, a setting in user defaults....

What is app launch time?

The time to initial display (TTID) metric measures the time it takes for an application to produce its first frame, including process initialization (if a cold start), activity creation (if cold/warm), and displaying first frame.


1 Answers

This should point you in the right direction:

static NSString* const hasRunAppOnceKey = @"hasRunAppOnceKey";
NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
if ([defaults boolForKey:hasRunAppOnceKey] == NO)
{
    // Some code you want to run on first use...
    [defaults setBool:YES forKey:hasRunAppOnceKey];
}
like image 84
Matt Wilding Avatar answered Nov 11 '22 08:11

Matt Wilding