i like to show the push notification count like this ,i have searched about it but can't get the right solution.
If you want to change badge with number, you can be changed in NOTIFICATION SETTING on the notification panel or Settings > Notifications > App icon badges > Select Show with number. Skip to Step 4 if you use this method. Screen Images are for reference only.
Right-click on drawable > new > vector asset > search for notification icon and select > finish. We are going to use this icon to show our notification count on top of it.
Step 1: Launch the Settings app on your iPhone or iPad. Step 2: Tap Home screen. Step 3: In the Notification badges section, toggle on the switch for Show in App Library. Step 4: If seeing the badge in your App Library is preferable, just switch the toggle back on for the full effect.
You can set it everywhere. E.g:
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:123]; // this one
}
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 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/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With