Created
September 13, 2010 19:57
-
-
Save soffes/577915 to your computer and use it in GitHub Desktop.
Is there a better way?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Original | |
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { | |
static NSString *firstLaunchKey = @"firstLaunch"; | |
// Register default defaults | |
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults]; | |
NSDictionary *defaultDefaults = [[NSDictionary alloc] initWithObjectsAndKeys: | |
[NSNumber numberWithBool:YES], firstLaunchKey, | |
nil]; | |
[userDefaults registerDefaults:defaultDefaults]; | |
[defaultDefaults release]; | |
// First launch | |
if ([userDefaults firstLaunchKey] == YES) { | |
// Do first launch stuff here | |
[userDefaults setBool:NO firstLaunchKey]; | |
} | |
// Finish initializing... | |
} | |
// One solution: | |
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { | |
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"hasLaunched"] == NO) { | |
// First launch, do stuff... | |
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"hasLaunched"]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
According to the docs, the contents of the registration domain are not written to disk; you need to call this method (registerDefaults:) each time your application starts.
You can place a plist file in the application's Resources directory and call registerDefaults: with the contents that you read in from that file.