Use -applicationDidEnterBackground:
to save user data. This should also be done in -applicationWillTerminate:
which might get called if the battery dies, I guess. See this question for more info: ApplicationWillTerminate in iOS 4.0
For my app, I extensively researched this issue and I found out that besides implementing both above mentioned methods I had to check whether the device supported multi-tasking, otherwise data would get saved twice (e.g. on an iPhone 3G). So here is how that part of my code looks like:
- (void) applicationDidEnterBackground:(UIApplication*)application
{
// This is called on all iOS 4 devices, even when they don't support multi-tasking.
// But we want to avoid saving data twice, so we check.
if ([[UIDevice currentDevice] respondsToSelector:@selector(isMultitaskingSupported)])
[model serializeEntries];
}
- (void) applicationWillTerminate:(UIApplication*)application
{
// This is always called on devices that don't support multi-tasking,
// but also in low-memory conditions and when the app has to be quit for some
// other reason.
[model serializeEntries];
}