从以前的版本更新应用程序的最佳做法

时间:2011-03-29 15:48:29

标签: iphone ipad

我想知道在更新以前版本的应用时人们在做什么。除了核心数据模型更新之外,这可能包括添加新对象,删除旧对象等以支持新功能等。

目前我将更新代码放在方法

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

                }

0 个答案:

没有答案