Re: Implications of changing an app's bundle identifier
Re: Implications of changing an app's bundle identifier
- Subject: Re: Implications of changing an app's bundle identifier
- From: Bill Cheeseman <email@hidden>
- Date: Sun, 25 Feb 2007 16:08:19 -0500
- Thread-topic: Implications of changing an app's bundle identifier
on 2007-02-24 6:52 PM, Darkshadow at email@hidden wrote:
> For the preferences, I moved them over by simply doing this in the +initialize
> method in my app delegate:
>
> + (void)initialize
> {
> NSDictionary *oldPrefs = [[NSUserDefaults standardUserDefaults]
> persistentDomainForName:@"old.bundle.identifier"];
> if ( oldPrefs ) {
> [[NSUserDefaults standardUserDefaults] setPersistentDomain:oldPrefs
> forName:[[NSBundle mainBundle] bundleIdentifier]];
> [[NSUserDefaults standardUserDefaults]
> removePersistentDomainForName:@"old.bundle.identifier"];
> [[NSUserDefaults standardUserDefaults] synchronize];
> }
>
> /* Whatever else you may have been doing here */
> }
>
> That was all I needed to do when I changed the bundle identifier, but then I
> didn't have anything else that was dependent on it.
That seems right if you want to trash the old preferences file right away.
However, I think I want to keep the old preferences file around in case a
user decides not to use the new version of my app and downgrades to the old
version. In that scenario, I need to make sure the old preference settings
are adopted for the new version of the app the first time the user runs it,
but that the old preference settings are ignored by the new app thereafter.
The right logic to do this seems to be: (1) test for the existence of a
preferences file for the new app; (2) if not found, test for the existence
of a preferences file for the old app; (3) if found, adopt the old settings
and create a new preferences file with them; (4) if not found, set and
register initial defaults for the new app. In step (3), you might also have
to set defaults for any new options not present in the old preferences file.
In my app, it would go like this:
+ (void)initialize {
if (self == [UIActionsApplication class]) {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if (![[defaults persistentDomainNames]
containsObject:@"new.bundle.identifier"]) {
// If there is no preferences file for this new version of the
application, then ...
NSDictionary *oldPrefs = [defaults
persistentDomainForName:@"old.bundle.identifier"];
if (oldPrefs) {
// ... look for a preferences file for the old version of
the application and, if found, turn it into a preferences file for this new
version. This should happen only the first time the user runs the new
version, so that subsequent user changes to the new preferences file
settings stick instead of reverting to the old preference file settings. The
old preferences file is left in place in case the user downgrades to the old
version after trying out the new version.
[defaults setPersistentDomain:oldPrefs
forName:@"new.bundle.identifier"];
[defaults synchronize];
} else {
// If there is no preferences file for the old version of
the application, either, then register initial user defaults.
NSDictionary *initialUserDefaults = [NSDictionary
dictionary]; // or whatever
[defaults registerDefaults:initialUserDefaults];
}
}
}
}
Bill Cheeseman
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden