About the difference among the UIApplicationDelegate
methods, please refer to UIApplicationDelegate Protocol Reference. applicationDidEnterBackground:
will always be called when the home button is pressed. But it seems that applicationWillTerminate:
is not guaranteed to be called.
If your app is not running in foreground, it can be either in background mode or in suspended mode. Please refer to "The App Launch Cycle" section of iOS App Programming Guide - App States and Multitasking.
When the app is running in background and monitoring events, applicationWillTerminate:
will be called when it is terminated. When the app is suspended, it will not. See the description in "App Termination" section:
Even if you develop your app using iOS SDK 4 and later, you must still be prepared for your app to be killed without any notification. The user can kill apps explicitly using the multitasking UI. In addition, if memory becomes constrained, the system might remove apps from memory to make more room. Suspended apps are not notified of termination but if your app is currently running in the background state (and not suspended), the system calls the applicationWillTerminate:
method of your app delegate. Your app cannot request additional background execution time from this method.