How to determine the first startup of an iOS app

Source: Internet
Author: User

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];

}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.