方法一、在didFinishLaunchingWithOptions方法中加入如下代码:
if(![[NSUserDefaults standardUserDefaults] boolForKey:@"firstLaunch"]){此处测试可以通过
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"firstLaunch"];
//第一次启动
}else{
//不是第一次启动了
}
[[NSUserDefaults standardUserDefaults] removeObjectForKey:key];
方法二、判断app是否第一次启动或者更新后第一次启动
#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;
}
else if (![lastRunVersion isEqualToString:currentVersion]) {
[defaults setObject:currentVersion forKey:LAST_RUN_VERSION_KEY];
return YES;
}
return NO;
}
此处测试可以通过
改变bundle version