我想知道在更新以前版本的应用时人们在做什么。除了核心数据模型更新之外,这可能包括添加新对象,删除旧对象等以支持新功能等。
目前我将更新代码放在方法
中- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions;
这或多或少都是我所做的:
NSString *version = [userDefaults stringForKey:@"myAppVersion"];
if(!version){
// first time installation
NSString *bundleVersion = [[NSBundle mainBundle] objectForInfoDictionaryKey:(NSString *)kCFBundleVersionKey];
[userDefaults setValue:bundleVersion forKey:@"myAppVersion"];
[userDefaults synchronize];
// other code here to handle initial installation
}
else{
NSString *updatedTov1.1 = [defaults objectForKey:@"updatedTov1.1"];
if(!updatedTov1.1){
// updating from a previous version to version v1.1
// set current version
NSString *bundleVersion = [[NSBundle mainBundle] objectForInfoDictionaryKey:(NSString *)kCFBundleVersionKey];
[userDefaults setValue:bundleVersion forKey:@"myAppVersion"];
// other code to handle update
defaults setObject:@"updatedTov1.1" forKey:@"updatedTov1.1"];
[userDefaults synchronize];
}
}