Ben Packard
Ben Packard

Reputation: 26476

How are multiple app updates applied?

I have released version 1.0 of my app. Version 1.1 will likely include some kind of migration code. For argument's sake, let's say it will update a core data attribute - all last names will be converted to uppercase. I will execute this code on first launch in version 1.1.

Will I need to keep this code in place for all subsequent versions? If a user skips 1.0 and only updates when 1.2 is released, will 1.1 be applied first automatically? Or do I need to keep checking whether to update the last names in all versions forever?

Upvotes: 3

Views: 109

Answers (2)

DrummerB
DrummerB

Reputation: 40211

You don't release updates, you release new versions. If someone updates from 1.0 to 1.2 and skips 1.1, than that's exactly what's happening. 1.1 will never be installed or executed.

EDIT:

Here is a suggestion for a very simple way to manage updates. Probably not the most elegante one, but it works.

NSString *lastVersion = [[NSUserDefaults standardUserDefaults]
                         stringForKey:@"LastVersion"];
NSString *currentVersion = [[NSBundle mainBundle]
            objectForInfoDictionaryKey:@"CFBundleShortVersionString"];

if ([self version:lastVersion isSmallerThanVersion:@"1.1"]) {
    // update from 1.0 to 1.1 here.
}
if ([self version:lastVersion isSmallerThanVersion:@"1.2"]) {
    // update from 1.1 to 1.2 here.
}
if ([self version:lastVersion isSmallerThanVersion:@"1.3"]) {
    // update from 1.2 to 1.3 here.
}

[[NSUserDefaults standardUserDefaults]
  setObject:currentVersion forKey:@"LastVersion"];

In this example you had 4 versions (1.0, 1.1, 1.2, 1.3) and 1.3 is the newest release.

You run this on every launch of your app. Since updating the app also terminates it, you can assume that this will run after a possible update.

Basically you load the last version that the user used on this device from the user defaults. If the app launches for the first time ever, there will be no known previous versions, none of the update routines are executed and the current version (1.3) is saved as the last used version.

If the app was used with the previous version (1.2), then lastVersion will be 1.2 and only the last if block is executed.

If the app was used with version 1.1, but skipped 1.2 and was now updated to 1.3, lastVersion will be 1.1 and the last two if blocks are executed sequentially. So first you update your data from 1.1 to 1.2, then from 1.2 to 1.3.

Upvotes: 2

Paramasivan Samuttiram
Paramasivan Samuttiram

Reputation: 3738

You should keep the migration code for all versions > 1.0

Upvotes: 2

Related Questions