How to show the notification count in app icon?
11,784
Solution 1
You can set it everywhere. E.g:
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:123]; // this one
}
Solution 2
When you receive your notification this method is got called:
application:didReceiveRemoteNotification:
This will contain a NSDictionary
`(NSDictionary *)userInfo`
update the app icon badge count using the function
[UIApplication sharedApplication].applicationIconBadgeNumber = [[[userInfo objectForKey:@"aps"] objectForKey: @"badgecount"] intValue];
Your Payload look like this:
{
"aps" : {
"alert" : "You got your emails.",
"badge" : 9
}
}
To hide the badge use Zero(0)
Solution 3
Its called badge, you can write following line to achieve this:
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:22];
Please refer to following link if you want to understand its working in sample application:
http://www.touch-code-magazine.com/how-to-add-a-badge-to-the-application-icon/
![Kishore Kumar](https://lh4.googleusercontent.com/-KEdmw7aZRjo/AAAAAAAAAAI/AAAAAAAAAn8/5yF0KqEnn4o/photo.jpg?sz=256)
Author by
Kishore Kumar
IT is the platform where we can make things from harder to easier , I am part of it , That is making me more happy to continue my work , Software engineer and Business analyst .
Updated on June 08, 2022