How iOS can tell the app to start for the first time

Source: Internet
Author: User

In APPDELEGATE.M, locate the "Application:didfinishlaunchingwithoptions:" Method and add the following code:
    1. if (![ [Nsuserdefaults Standarduserdefaults] boolforkey:@ "everlaunched"]) {
    2. [[Nsuserdefaults Standarduserdefaults] setbool:yes forkey:@ "everlaunched"];
    3. [[Nsuserdefaults Standarduserdefaults] setbool:yes forkey:@ "Firstlaunch"];
    4. }
    5. else{
    6. [[Nsuserdefaults Standarduserdefaults] setbool:no forkey:@ "Firstlaunch"];
    7. }

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:

  1. if ([[[Nsuserdefaults Standarduserdefaults] boolforkey:@ "Firstlaunch"]) {
  2. Here to determine whether the first time
  3. Uialertview *alert=[[uialertview Alloc] initwithtitle:@ "First time"
  4. message:@ "Go to App"
  5. Delegate:self
  6. cancelbuttontitle:@ "I know."
  7. Otherbuttontitles:nil];
  8. [Alert show];
  9. [Alert release];
  10. }

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

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.