5

I'm using applicationWillTerminate: to save some last-minute stuff. But the problem is that it never gets called. If I do something like this at the top of the method: NSLog(@"Something"); it doesn't get called and doesn't get outputted to the console.

Does anyone know why this is happening?

jscs
  • 63,694
  • 13
  • 151
  • 195
TheHAWK
  • 99
  • 1
  • 5

4 Answers4

12

From Apple docs:

For applications that do not support background execution or are linked against iOS 3.x or earlier, this method is always called when the user quits the application. For applications that support background execution, this method is generally not called when the user quits the application because the application simply moves to the background in that case. However, this method may be called in situations where the application is running in the background (not suspended) and the system needs to terminate it for some reason.

If your app has background enabled use:

- (void)applicationDidEnterBackground:(UIApplication *)application

zaph
  • 111,848
  • 21
  • 189
  • 228
  • Why is my didEndCustomizingItems method not being called either, when I put a NSLog into it it doesn't output anything. – TheHAWK Sep 14 '11 at 13:31
  • 2
    An important caveat: on iOS 6 at least, `applicationWillTerminate:` is called *without* the app ever having been backgrounded if the user powers the device off while the app is still in the foreground. – smorgan Mar 08 '13 at 10:00
5

Use applicationDidEnterBackground: instead. Applications aren't terminated when you press the home button in a multitasking system.

jrturton
  • 118,105
  • 32
  • 252
  • 268
  • 1
    Not applicationWillEnterBackground:, that method does not exist, use applicationDidEnterBackground: – zaph Sep 14 '11 at 13:32
1

step 1: command + shift + h (double click(tab))

step 2: move app top side (kill)

step 3: applicationWillTerminate Work

gowthaman-mallow
  • 692
  • 1
  • 6
  • 10
1

From the iOS Application Programming Guide on Core Application Design and Application life time:

The applicationWillTerminate: method is not called if your application is currently suspended.

If you are linking against iOS 4.0, you should also save data in applicationDidEnterBackground:.

Mats
  • 8,528
  • 1
  • 29
  • 35