views:

218

answers:

2

Hi,

I want to store / save personal preference settings like Email, Phone number for an App. I have few forms which send info by Email to my ID. I want to know the Email & Phone number of user so I can contact this person if need be. I don't want users to keep entering their Email ID & Phone No. everytime in each form. It's wise to take these inputs (Email & Phone) just once per device / per App installed on the device.

I am trying to use .plist for this purpose. I have no success. How do I do it? Any example code (or) links?

Thanks. I would appreciate any help.

+2  A: 

You might want to check out NSUserDefaults:

// Storing values
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
[prefs setObject:@"[email protected]" forKey:@"userMail"];
[prefs synchronize];
// Reading values, even after application restart
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
NSString *mail = [prefs stringForKey:@"userMail"];
zoul
I was able to resolve this by storing data in a .plist file. And reading from the same. Code reference: Examples project : 11 Persistence PListWorks like a charm.
sg
A: 

Why don't you use NSUserDefaults? The only thing I found is important to take heed of is to synchronize when the user quits the app (in the applicationWillTerminate method of the app delegate.

mvexel
I understand from the docs that this is not necessary, the synchronize is automatically called when app exits.
Jaanus
I don’t think that’s true. The `synchronize` method is called periodically, but not when the application exits. The docs say that you should call `synchronize` by hand if you know your application is about to quit.
zoul
I was able to resolve this by storing data in a .plist file. And reading from the same. Code reference: Examples project : 11 Persistence PList Works like a charm.
sg