I use NSUserDefaults in my settings. The application works well, even if I press the home button to turn on the application in the background, but if I kill the application, the data stored in NSUserDefaults will be lost. Here is my code. I have a sync. First initialization:
if (![userDefaults integerForKey:
kORFootageAirPlayModeKey])
{
[userDefaults setInteger:TRUE forKey:kORFootageAirPlayModeKey];
}
[userDefaults synchronize];
Reading the value in viewController:
airPlayMode = [[NSUserDefaults standardUserDefaults]integerForKey:kORFootageAirPlayModeKey];
Set it to action:
- (IBAction)changeAirPlayStatus:(id)sender
{
if (sender)
{
airPlayMode = [sender tag];
[[NSUserDefaults standardUserDefaults] setInteger:airPlayMode forKey:kORFootageAirPlayModeKey];
[[NSUserDefaults standardUserDefaults] synchronize];
}
.....
}
source
share