How do you call a method on only the initial launch of an application? For example, if you wanted to put a tutorial UIAlertView on the very first launch but never again after that?
Asked
Active
Viewed 214 times
0
-
Pretty much a duplicate of http://stackoverflow.com/questions/308832/iphone-the-quickest-easiest-way-to-detect-first-launch – James Aug 09 '10 at 19:40
2 Answers
2
Easy. When your app launches, check [NSUserDefaults standardUserDefaults]
for the presence of a bool that you put in there. If the boolean isn't there (or it's not YES), then show the alert and save the boolean back into NSUserDefaults
as YES
.
It's all of about 4 lines of code:
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"HasShownInitialAlert"] == NO) {
UIAlertView * alert = [[UIAlertView alloc] init...];
[alert show];
[alert release];
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"HasShownInitialAlert"];
}

Dave DeLong
- 242,470
- 58
- 448
- 498
0
Use the NSUserDefaults for this. Store a BOOL there saying if its firstlaunch, and set it in applicationDidFinishLaunching. Then then only time that is false is after fresh installs of the app.

Joshua Weinberg
- 28,598
- 2
- 97
- 90