5

i like to show the push notification count like this ,i have searched about it but can't get the right solution.

enter image description here

Wide Angle Technology
  • 1,184
  • 1
  • 8
  • 28
Kishore Kumar
  • 4,265
  • 3
  • 26
  • 47
  • 2
    Refer http://stackoverflow.com/questions/6797037/how-to-add-notifications-to-icon-in-ios-application. – Rince Thomas Jan 06 '16 at 08:55
  • 2
    Possible 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 Answers4

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
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