Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show the notification count in app icon?

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

like image 400
Kishore Kumar Avatar asked Jan 06 '16 08:01

Kishore Kumar


People also ask

How do I get my app icon to show notification numbers?

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.

How do I display the count of notifications in the toolbar icon in Android?

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.

How do I get notification number for app icon on iPhone?

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.


3 Answers

You can set it everywhere. E.g:

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

{
    [[UIApplication sharedApplication] setApplicationIconBadgeNumber:123]; // this one
} 
like image 156
tuledev Avatar answered Oct 11 '22 13:10

tuledev


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)

like image 36
Rahul Avatar answered Oct 11 '22 13:10

Rahul


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/

like image 27
Aamir Avatar answered Oct 11 '22 15:10

Aamir