I would like to update an app to add a tour on first launch. I would ordinarily handle this with some kind of NSUserDefaults
key. However, there are pre-existing existing versions of the app already released.
How can I trigger some behavior on first launch of the app, but only for fresh installs and not for the first launch after an update?
you can check app version via web service. and warn users to update the app. And this case, internet connection required.
On launch, check for the existence of a file/persistent setting with a name unique to the currently running version. If it's not there, show the tour, then touch the file/create the persistent setting.
The best approach I can identify so far is to first release a version without the tour but that does record some kind of flag to NSUserDefaults. Then I can hope that most existing users will update and use the app before I launch a second update including the tour.
I can combine this with @rmaddy's suggestion to look for any other previously existing settings that might have been written to increase my coverage.
This is obviously far from ideal.
The easiest way is to save the current version using NSUserDefaults
:
if (![[NSUserDefaults standardUserDefaults] objectForKey:@"app_version"] || [[[NSUserDefaults standardUserDefaults] objectForKey:@"app_version"] integerValue] < [[[NSBundle mainBundle] objectForInfoDictionaryKey: @"CFBundleVersion"] integerValue]) {
// new version detected!
[[NSUserDefaults standardUserDefaults] setObject:[[NSBundle mainBundle] objectForInfoDictionaryKey: @"CFBundleVersion"] forKey:@"app_vervion"];
}
EDIT Added check for user defaults existence for first update containing this functionality.
EDIT II I now understood what you really want. You'll need almost the same code I wrote:
if (![[NSUserDefaults standardDefaults] boolForKey:@"tour_done"]) {
// present tour and that call:
// [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"tour_done"];
// [[NSUserDefaults standardUserDefaults] synchronize];
}