Search code examples
ipadios4xcode4

applicationWillTerminate not called when application stopped from Xcode


I have got into an strange issue, where the - (void)applicationWillTerminate:(UIApplication *)application{} and - (void)applicationDidEnterBackground:(UIApplication *)application{} are not called when I try to stop the application from Xcode as opposed to home button.


Solution

  • This behavior is expected, because Xcode is not the home button on your iOS device.

    If you click "Build and Run", for example, while testing another app, you will be prompted to kill the first app. If you do, then the first app will close as if it never opened. This seems to be a consequence of the application sandboxing.

    On a similar note, If you hit the home button while testing an app on a multitasking capable device, then the app will continue to run in background mode and it will not trigger applicationWillTerminate. Your device should however, trigger applicationDidEnterBackground.