Determine if the app is the first time it starts

Source: Internet
Author: User

How to tell if the app is the first boot, when the first boot, loading the boot page, etc.

Here is my solution:

1. Found in "AppDelegate.h"-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (nsdictionary *) Launchoptions method, 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"];}




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 timeHdisplayview*HVC = [[Hdisplayview alloc]initwithframe:cgrectmake (0,0, Mainscreen_width, Mainscreen_height)];                [Self.window.rootViewController.view ADDSUBVIEW:HVC]; [UIView animatewithduration:0.25animations:^{hvc.frame= CGRectMake (0,0, Mainscreen_width, mainscreen_height);            }]; }

@ "Firstlaunch" will be set to NO.

Determine if the app is the first time it starts

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.