i like to show the push notification count like this ,i have searched about it but can't get the right solution.
Asked
Active
Viewed 1.4k times
5

Wide Angle Technology
- 1,184
- 1
- 8
- 28

Kishore Kumar
- 4,265
- 3
- 26
- 47
-
2Refer http://stackoverflow.com/questions/6797037/how-to-add-notifications-to-icon-in-ios-application. – Rince Thomas Jan 06 '16 at 08:55
-
2Possible duplicate of [Updating iOS badge without push notifications](http://stackoverflow.com/questions/4861131/updating-ios-badge-without-push-notifications) – serhat sezer Jan 06 '16 at 09:04
4 Answers
11
You can set it everywhere. E.g:
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:123]; // this one
}

tuledev
- 10,177
- 4
- 29
- 49
-
-
i like to do auto update of notification count ,so i tried [[UIApplication sharedApplication] setApplicationIconBadgeNumber:[UIApplication sharedApplication].applicationIconBadgeNumber]; but didn't get . – Kishore Kumar Jan 06 '16 at 10:35
-
i gave this line of code inside pushnotification did receive method – Kishore Kumar Jan 06 '16 at 10:36
-
Are you sure it call the line? And more you should +1 `[[UIApplication sharedApplication] setApplicationIconBadgeNumber:[UIApplication sharedApplication].applicationIconBadgeNumber+1];` – tuledev Jan 06 '16 at 10:37
-
yes this line called and when i click the notification its again shown 1. – Kishore Kumar Jan 06 '16 at 10:39
4
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)

Rahul
- 5,594
- 7
- 38
- 92
1
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/

Aamir
- 16,329
- 10
- 59
- 65
0
In swift 4 you can set badge by adding this line:
UIApplication.shared.applicationIconBadgeNumber = <Int_count>

Er. Vihar
- 1,495
- 1
- 15
- 29