In APPDELEGATE.M, locate the "Application:didfinishlaunchingwithoptions:" Method 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 total solution is 2 key: @ "everlaunched" to determine if the user has previously logged in,
@ "Firstlaunch" is used by developers to judge in other parts of the program.
At the first boot, key @ "everlaunched" is not assigned and is set to Yes. @ "Firstlaunch" is set to YES.
In other parts of the program, use the following code to determine:
- if ([[[Nsuserdefaults Standarduserdefaults] boolforkey:@ "Firstlaunch"]) {
- Here to determine whether the first time
- Uialertview *alert=[[uialertview Alloc] initwithtitle:@ "First time"
- message:@ "Go to App"
- Delegate:self
- cancelbuttontitle:@ "I know."
- Otherbuttontitles:nil];
- [Alert show];
- [Alert release];
- }
The first piece of code running key @ "Firstlaunch" will be set to NO.
Transferred from: http://blog.csdn.net/justinjing0612/article/details/7306836
How iOS can tell the app to start for the first time