In my app I'm using an NSUserDefaults object to store the username, password and server URL in the built-in Settings app. If there is no data saved, the user is presented a login interface and upon succesful login the username and password are saved. Then in my app I have a view which displays this information, but the text is missing as if the data hasn't been saved to the Settings yet. Here's the code:
...
NSUserDefaults* appSettings = [NSUserDefaults standardUserDefaults];
[appSettings setObject:username forKey:USERNAME];
[appSettings setObject:password forKey:PASSWORD];
if ( [appSettings synchronize] ) {
// display an alert with a positive message
} else {
// display an alert with a negative message
}
So, after logging in the positive message is displayed, but when I fetch the data again there is nothing there, unless I restart the app.
What do I need to do to save the data immediatly, or at least before another view controller needs to read the settings?