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