i like to show the push notification count like this ,i have searched about it but can't get the right solution.
How to show the notification count in app icon?
Refer #6797537. –
Sufflate
Possible duplicate of Updating iOS badge without push notifications –
Spline
You can set it everywhere. E.g:
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:123]; // this one
}
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 method –
Aglaia
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
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)
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:
In swift 4 you can set badge by adding this line:
UIApplication.shared.applicationIconBadgeNumber = <Int_count>
© 2022 - 2024 — McMap. All rights reserved.