Using NSDictionary to write to /Library/Prefererences
Using NSDictionary to write to /Library/Prefererences
- Subject: Using NSDictionary to write to /Library/Prefererences
- From: John Cebasek <email@hidden>
- Date: Mon, 7 Feb 2005 16:18:18 -0500
Hi All:
I'm attempting to write into /Library/Preferences to store my preferences. The reason that I need to write to /Library/Preferences, it that I'm a loginwindow bundle and no one has logged in when I need to write to the preferences file.
When I was testing, I was using ~/Library/Preferences to store my file and no errors were reported. Using /Library/Preferences, I get back a NO from writeToFile.
Here's a snippet of the code:
-(void) writeCRYPTOLogonPrefs
{
FunctionTrace trace("Login", "CRYPTOLogonGUI", "writeCRYPTOLogonPrefs");
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSMutableDictionary *prefs;
int nWhichPage = [self getDialogPage];
// allocate an NSMutableDictionary to hold our preference data
prefs = [[NSMutableDictionary alloc] init];
//
// Turn the int into a string
//
NSString *sPageNum = [NSString stringWithFormat:@"%d", nWhichPage];
//
// Set which page we're on
//
[prefs setValue:sPageNum forKey:@"PageNum"];
//
// If we're on the hardware page, write out the username
//
if (nWhichPage == HARDWARE_TOKEN_PAGE)
{
[prefs setValue:[userNameTextField stringValue] forKey:@"UserName"];
}
//
// save our preferences list to the /Library/Preferences directory
//
if ([prefs writeToFile:[@"/Library/Preferences/TimHortons.plist" stringByExpandingTildeInPath] atomically: TRUE] == YES)
{
trace.stream() << "Preferences write succeeded." << endl;
}
else
{
trace.stream() << "Why'd it fail?" << endl;
}
[pool release];
}
I left the stringByExpandingTildeInPath because the docs say the string is returned unaltered if there's no '~'.
Any comments on what I'm missing?
John
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden