I searched a lot for a solution to handle icon badging while the application is not running.
I wrote an app that receives push notifications but, while in running state i can update the badge in the application:didReceiveRemoteNotification: function, i still can’t figure out how to update the icon badge while the application is not running.
The “Badge App Icon” switch is ON under the notifications menu of my app but when receiving remote notifications the icon badge is not updated.
The code is running on a device, no simulator involved.
My notification contains a badge
$body['aps'] = array(
'alert' => $message,
'sound' => 'default',
'badge' => '1' // Wrong, see edit...
);
I’m using a simple php script to generate it.
Am i missing something?
Edit:
I found out that i was sending the badge properties as a string instead of a number.
The correct code in php is:
$body['aps'] = array(
'alert' => $message,
'sound' => 'default',
'badge' => 1 // Right
);
With the numeric badge value the icon badge is correctly updated.
When the system receives a push notification it checks whether the notification contains a badge number. If it does it will set your apps badge to that number.
Are you setting the badge number in the push notification?