Arsh Avo
Arsh Avo

Reputation: 29

ios applicationwillenterbackground not being called

I am trying to save my data when I exit or minimize my application, but it seems like applicationwillenterbackground is never called. Do I need to do anything specific?

I have set the <UIApplicationDelegate> in detailview.h class but still no luck.

By the way, I am using Master-DetailView templete if this is relavent.

Upvotes: 0

Views: 2401

Answers (1)

vbwx
vbwx

Reputation: 388

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

Upvotes: 1

Related Questions