I want to cancelAllLocalNotifications and setApplicationIconBadgeNumber to 0 when my application is terminated (either by the OS or by double tapping the home button and kil
applicationWillTerminate:
is not called by the OS when it kills your app. The OS just kills the process without notifying your app about it. There is no documented way to execute code at this moment.
You should use applicationWillResignActive: instead.
Starting with iOS 4.0 applicationWillTerminate is not called for applications when they are killed in the background. Apps are put in the background when you hit the home button now or otherwise switch apps.