How to determine the first launch of the iOS app and the first launch after each update

Source: Internet
Author: User

The popular solution is a key in most places where [Nsuserdefaults standarduserdefaults] is used, if it does not exist, which means that this is the first time the application is started, otherwise it is not the first boot

In APPDELEGATE.M, locate the "Application:didfinishlaunchingwithoptions:" Method and add the following code:

1 if(! [[Nsuserdefaults Standarduserdefaults] Boolforkey:@"Firstlaunch"]) {2[[Nsuserdefaults Standarduserdefaults] Setbool:yes forkey:@"Firstlaunch"];3NSLog (@"first time start");4}Else{5NSLog (@"non-first time start");6}

This is very effective for the first installation, but if the program installs the upgraded version, the Firstlaunch is already there and will no longer run.

If you need to determine the first run after each app update, refer to the following code

#define Last_run_version_key        @ "Last_run_version_of_application"-(BOOL) isfirstload{    NSString * CurrentVersion = [[[NSBundle Mainbundle] infodictionary]                                objectforkey:@ "cfbundleshortversionstring"];    Nsuserdefaults *defaults = [Nsuserdefaults standarduserdefaults];    NSString *lastrunversion = [defaults objectforkey:last_run_version_key];    if (!lastrunversion) {        [defaults setobject:currentversion forkey:last_run_version_key];        return YES;        APP is being run for first time    }else if (![ Lastrunversion Isequaltostring:currentversion]) {        [defaults setobject:currentversion forkey:last_run_version_ KEY];        return YES;        APP has been updated since last run    }    return NO;

  

  

How to determine the first launch of the iOS app and the first launch after each update

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.