How to show the notification count in app icon?
Asked Answered
A

4

7

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

Aglaia answered 6/1, 2016 at 8:54 Comment(2)
Refer #6797537.Sufflate
Possible duplicate of Updating iOS badge without push notificationsSpline
T
14

You can set it everywhere. E.g:

-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo

{
    [[UIApplication sharedApplication] setApplicationIconBadgeNumber:123]; // this one
} 
Teeters answered 6/1, 2016 at 8:56 Comment(5)
anhtu bro one help ?Aglaia
i like to do auto update of notification count ,so i tried [[UIApplication sharedApplication] setApplicationIconBadgeNumber:[UIApplication sharedApplication].applicationIconBadgeNumber]; but didn't get .Aglaia
i gave this line of code inside pushnotification did receive methodAglaia
Are you sure it call the line? And more you should +1 [[UIApplication sharedApplication] setApplicationIconBadgeNumber:[UIApplication sharedApplication].applicationIconBadgeNumber+1];Teeters
yes this line called and when i click the notification its again shown 1.Aglaia
P
5

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)

Plater answered 6/1, 2016 at 9:3 Comment(0)
F
1

Its called badge, you can write following line to achieve this:

[[UIApplication sharedApplication] setApplicationIconBadgeNumber:22];

Please refer to this link if you want to understand its working in sample application:

Fluent answered 6/1, 2016 at 9:4 Comment(0)
V
1

In swift 4 you can set badge by adding this line:

UIApplication.shared.applicationIconBadgeNumber = <Int_count>
Vizza answered 13/9, 2019 at 4:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.