判斷app是否是第一次執行

weixin_33866037發表於2017-02-18

#define LAST_RUN_VERSION_KEY @"last_run_version_of_application"

//判斷app是否是第一次執行/更新後第一次執行

-(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;

}

相關文章