How to tell if an app is running after first run or upgrade after it's installed in iOS

Source: Internet
Author: User

For first-time installed apps, you can use the following methods to determine

[[Nsuserdefaults Standarduserdefaults] boolforkey:@ "Firstlaunch"];

If the app is upgraded via the App Store, you can use the version number to determine

[[[NSBundle Mainbundle] infodictionary] objectforkey:@ "cfbundleversion"];

Actual use can add the following code in Didfinishlaunchingwithoptions:

    if (![ [Nsuserdefaults Standarduserdefaults] boolforkey:@ "Firstlaunch"]) {[[Nsuserdefaults standarduserdefaults] SetBool:        YES forkey:@ "Firstlaunch"];        NSLog (@ "launch app for the first time after installation"); Get the current app version number and deposit it in nsuserdefaults nsstring* appversion = [[[NSBundle Mainbundle] infodictionary] objectforkey:@ "CFBund        Leversion "];        Nsuserdefaults *userdefaults = [Nsuserdefaults standarduserdefaults];        [Userdefaults setobject:appversion forkey:@ "appversion"];    [Userdefaults Synchronize]; } else {//depending on the version number to determine if the update was first started after nsstring* appversion = [[[NSBundle Mainbundle] infodictionary] objectforkey:@        "Cfbundleversion"];        Nsuserdefaults *userdefaults = [Nsuserdefaults standarduserdefaults];        nsstring* localversion = [userdefaults stringforkey:@ "appversion"];        if ([appversion isequaltostring:localversion]) {NSLog (the app is not first opened after installation or upgrade);            } else {NSLog (the app is first opened after upgrade);    Deposit the current app version number in Nsuserdefaults        [Userdefaults setobject:appversion forkey:@ "appversion"];        [Userdefaults Synchronize]; }    }

How to tell if an app is running after first run or upgrade after it's installed in iOS

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.