I have seen this problem many times. I took the time to study it today.
Adding help or promotion animations to the first running application is now very important.
A useful example is to send an analysis instance. This may be a good way to determine how many people download the utility. Someone will say, "But, hey, the apple appstore has already told me that the app has been downloaded ".
The popular solution is a key in most cases to use [nsuserdefaults standarduserdefaults. If it does not exist, it means that this is the application startup; otherwise, it is not the first time. Then it says the key to setting it to the latter in this method: "applicationwillterminate :( uiapplication *) application ". This solution is very good until we get IOS 4.0. In IOS 4.0 +, this method is rarely called (only applicable to memory problems) as described in Apple's uiapplicationdelegate document ....
You can search for the key, if it is not set to run first-time-code, and set it, but in the rest of the app, you won't be able to know if it is running for the first time (unless you use a global variable)
Therefore, I suggest my solution :...
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];
}