I'm setting :
- (void)applicationWillTerminate:(UIApplication *)application
{
[UIApplication sharedApplication].applicationIconBadgeNumber = 1;
}
in my application delegate but the badge is never updated... What can be the problem ?
How may I do to update that badge when the app is killed (phone shutdown, taskbar app kill, app killed by the system because of a memory overload, ...) ?
When your app is terminated in the background, it does not get an opportunity to clean up after itself. The app is already suspended when backgrounded; when killed it is just removed from RAM. Your badge updates need to happen before that time.
From the Apple docs:
Suspended
The app is in the background but is not executing code. The system moves apps to this state automatically and does not notify them before doing so. While suspended, an app remains in memory but does not execute any code.
When a low-memory condition occurs, the system may purge suspended apps without notice to make more space for the foreground app.
Also:
applicationWillTerminate:—Lets you know that your app is being terminated. This method is not called if your app is suspended.
Throw an NSLog(@"App is being terminated.");
into your -applicationWillTerminate:
method. I think you'll find that this method isn't being called when you are terminating the app the way you are.
You could set the application's badge icon during the app's normal execution or when the app is launched.
Please go over the app lifecycle documentation as below
Also try and see which of the below methods are being called
applicationWillResignActive:
applicationDidEnterBackground: