Find the "application: didfinishlaunchingwitexceptions:" method in appdelegate. m and add the following code:
If (! [[NSUserDefaults standardUserDefaults] boolForKey: @ "everLaunched"]) {
[[NSUserDefaults standardUserDefaults] setBool: YES forKey: @ "everLaunched"];
[[NSUserDefaults standardUserDefaults] setBool: YES forKey: @ "firstLaunch"];
}
Else {
[[NSUserDefaults standardUserDefaults] setBool: NO forKey: @ "firstLaunch"];
}
The general solution is to use two keys: @ "everLaunched" to determine whether the user has logged on before,
@ "FirstLaunch" is used to determine other parts of the program.
When the key @ "everLaunched" is started for the first time, the key @ "everLaunched" will not be assigned an address and is set to YES. @ "firstLaunch" to YES.
Use the following code to determine other parts of the program:
If ([[NSUserDefaults standardUserDefaults] boolForKey: @ "firstLaunch"]) {
// Determine whether it is the first time
UIAlertView * alert = [[UIAlertView alloc] initWithTitle: @ "First time"
Message: @ "Enter App"
Delegate: self
CancelButtonTitle: @ "I know"
OtherButtonTitles: nil];
[Alert show];
[Alert release];
}
The first code running key @ "firstLaunch" will be set to NO.
It has been tested. The above method is more effective and easier than I thought.
From andy Pan's column