Reputation: 167
I need the count value of unread as badge number.and badge number of app icon has to reduced and increase according to the unread message count.(increase if new unread message ,reduced if unread message is read)
->["Unread
" is the count of unread messages.]
NSString *unread =[[NSUserDefaults standardUserDefaults]valueForKey:@"unread"];
int badge = [unread intValue];
[UIApplication sharedApplication] setApplicationIconBadgeNumber:badge];
Upvotes: 0
Views: 2545
Reputation: 292
Usually the badge number is set by the OS when you receive JSON in the form of:
{
"aps" : {
"alert" : "New notification!",
"badge" : 2
}
}
So the server sets the badge number, meaning that you have to keep track of how many notifications a user has.
On the client side, you have to clear the notification like this:
application.applicationIconBadgeNumber = application.applicationIconBadgeNumber - 1; // Decrement counter
Or you can just set them all to 0 and assume they're all read once app is opened, like this:
application.applicationIconBadgeNumber = 0;
Upvotes: 2