Re: Using NSUserDefaults from a bundle-less app
Re: Using NSUserDefaults from a bundle-less app
- Subject: Re: Using NSUserDefaults from a bundle-less app
- From: Chris Parker <email@hidden>
- Date: Thu, 3 Apr 2003 17:59:39 -0800
Hi Robert,
On Thursday, April 3, 2003, at 5:29 PM, ROSE,ROBERT W
(HP-Corvallis,ex1) wrote:
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject: foo forKey: bar];
...
// program exits shortly after
This does absolutely nothing, that I can tell. I think it's because my
background app doesn't have a bundle... so how do I specify what
domain to
save these defaults in?
You'd need to call [defaults synchronize] to get this out to disk, but
that will use your background process' name to do it, since you don't
have a bundle ID.
You could use -[NSUserDefaults persistentDomainForName:] using the
domain ID you're using for the foreground application, copy the
resulting dictionary to be mutable, make changes to that and then use
-[NSUserDefaults setPersistentDomain:forName:] and synchronize.
Or...
You could use the CFPreferences API in your background tool to specify
the domain ID:
CFPreferencesSetValue(key, value, your.app.bundle.ID,
kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
CFPreferencesSynchronize(your.app.bundle.ID, kCFPreferencesCurrentUser,
kCFPreferencesAnyHost);
And that will work as well.
Remember that after you write & sync in one process, you'll have to
sync & read in the other to pick up the changes.
.chris
--
Chris Parker
Cocoa Frameworks Engineer
Apple Computer, Inc.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.