Reputation: 9703
Is there any way to increment a badge by one every time a push notification is received and the app is closed and not in the background?
I am currently managing the badge count on the server side and including the updated badge count in the payload. However in the case where multiple notifications need to be sent (such as a chat room situation), this is tedious and expensive on the server. Instead of passing an array of deviceToken's to the apns server I will need to loop through each device with the badge number for that device.
I would prefer to increment the badge count locally on the device when the push notification is received in ALL CASES including when the app is closed and not in the background.
Upvotes: 0
Views: 1404
Reputation: 8506
If you want to update the badge number upon receiving a notification, then you need to set the Badge
property of the json push notification to the desired number as follows:
{
"aps": {
"alert": "Test Push Notification",
"sound": "yourSound.aiff",
"Badge": "desiredNumber"
}
}
desiredNumber
will be the desired badge count
Upvotes: 2