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