Stored data lost after the kill application using NSUserDefaults

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];
    }
.....

}

+5
source share
2 answers

I see no reason for this.

You checked in the Simulator directory, in the Library / Caches section there is a plist that saves your NSUserDefaults. Check the spelling.

, , setInteger: TRUE. . setBOOL: YES. setInteger: 1.

+1

- -synchronize applicationWillTerminate: applicationWillResignActive: .

Edit:

, steipete setInteger: TRUE - setBool: YES .

+1

All Articles