Reputation: 27
I would like to ask, which method has been called whenever the user quit the app totally.
What I mean for quit the app totally is after the user tap the Home button, the app actually is running at the background but whenever the user double tap the Home button, then tap and hold on an app icon and then tap the RED MINUS sign to quit the app.
I'm trying to save my data whenever the app goes to background and load the data whenever the apps go back to active (foreground). It's work as long as I didn't quit the app totally.
If I quit the app by tapping the red minus sign and relaunch the app again, all my saved data is gone? Weird case is, sometimes it is saved and can be loaded, but mostly it won't be saved.
I have double check with my save method and try to NSLog it, I got the all the data saved but just don't know why it cannot be loaded after the user quit the app by tapping red minus sign.
Anyone know what happens on my app? BTW, I'm using NSUserDefaults to save my data and load my data.
[appDefaults setObject: object objectForKey: @"key"]; [appDefaults objectForKey: @"key"];
Upvotes: 0
Views: 238
Reputation: 57139
NSUserDefaults
saves the values you give it at periodic intervals, not necessarily by the time your application terminates. To make sure your settings get written to disk, call the -synchronize
method on your defaults object in -applicationWillTerminate:
.
Upvotes: 0
Reputation: 243156
Why wait until the application quits to save the data? Why not save it as soon as you get it?
However, if you have to save the data right before exiting, then use the: -[<UIApplicationDelegate> applicationWillTerminate:]
method.
Upvotes: 1