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: Mon, 26 Feb 2007 08:00:03 -0500
- Thread-topic: Implications of changing an app's bundle identifier
on 2007-02-25 8:29 PM, Bill Cheeseman at email@hidden wrote:
> on 2007-02-25 8:26 PM, Darkshadow at email@hidden wrote:
>
>> Bill, I don't know exactly how you're using preferences in your app, but
>> don't
>> you want to register the initial defaults *even if* you copy the old
>> preferences over?
>
> Yes, I think so. I actually ran my code after posting, and it didn't work
> right, apparently for this reason. More later.
For posterity, here's my final, tested code (irrelevant details removed).
Note that this is unusually complex because this application (UI Actions
Setup) uses two preferences files, one of the traditional kind and one
shared with a companion application (UI Actions).
+ (void)initialize {
if (self == [MainWindowController class]) {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
// Register initial user defaults.
NSDictionary *initialUserDefaults = [NSDictionary
dictionaryWithObjectsAndKeys:
@"YES", LAUNCH_UI_ACTIONS_AT_LOGIN_DEFAULTS_KEY,
@"YES", LAUNCH_UI_ACTIONS_AT_LAUNCH_DEFAULTS_KEY,
nil];
[defaults registerDefaults:initialUserDefaults];
// Transition from old preferences file name to new preferences file
name.
if (![[defaults persistentDomainNames]
containsObject:UI_ACTIONS_SETUP_DOMAIN_NAME]) {
// If there is no preferences file for this new version of the
application, then ...
NSDictionary *oldPrefs = [defaults
persistentDomainForName:UI_ACTIONS_SETUP_DOMAIN_NAME_OLD];
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:UI_ACTIONS_SETUP_DOMAIN_NAME];
}
}
// Transition from old shared suite preferences file name to new
shared suite preferences file name.
if (![[defaults persistentDomainNames]
containsObject:UI_ACTIONS_SUITE_DOMAIN_NAME]) {
// If there is no shared suite preferences file for this new
version of the application, then ...
NSDictionary *oldPrefs = [defaults
persistentDomainForName:UI_ACTIONS_SUITE_DOMAIN_NAME_OLD;
if (oldPrefs) {
// ... look for a shared suite 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.
// Update changed options for new shared suite preferences
file. In this product, the shared suite preferences file contains the bundle
version of both applications to help with synchronization.
NSMutableDictionary *tempOldPrefs = [oldPrefs mutableCopy];
NSNumber *uiActionsSetupVersion = [[NSBundle mainBundle]
objectForInfoDictionaryKey:@"CFBundleVersion"];
[tempOldPrefs setValue:uiActionsSetupVersion
forKey:UI_ACTIONS_SETUP_VERSION_SHARED_DEFAULTS_KEY];
NSNumber *uiActionsVersion = [[NSBundle
bundleWithPath:[[NSWorkspace sharedWorkspace]
absolutePathForAppBundleWithIdentifier:UI_ACTIONS_DOMAIN_NAME]]
objectForInfoDictionaryKey:@"CFBundleVersion"];
[tempOldPrefs setValue:uiActionsVersion
forKey:UI_ACTIONS_VERSION_SHARED_DEFAULTS_KEY];
oldPrefs = [tempOldPrefs copy];
[tempOldPrefs release];
[defaults setPersistentDomain:oldPrefs
forName:UI_ACTIONS_SUITE_DOMAIN_NAME];
[oldPrefs release];
}
}
[defaults synchronize];
}
}
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