• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Using NSDictionary to write to /Library/Prefererences
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: Using NSDictionary to write to /Library/Prefererences
      • From: Evan Schoenberg <email@hidden>
  • Prev by Date: "Subclass" NSMutableArray basic concept?
  • Next by Date: Re: "Subclass" NSMutableArray basic concept?
  • Previous by thread: Re: "Subclass" NSMutableArray basic concept?
  • Next by thread: Re: Using NSDictionary to write to /Library/Prefererences
  • Index(es):
    • Date
    • Thread