Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set the application badge number in ios 9

Tags:

I'd used

[UIApplication sharedApplication].applicationIconBadgeNumber = 5;

for setting application badge number. It's not working in ios 9 alone.

Can anyone suggest why?

I tried,

[[UIApplication sharedApplication] setApplicationIconBadgeNumber:5];
like image 632
Nazik Avatar asked Oct 26 '15 06:10

Nazik


People also ask

What is iOS notification badge count?

The iOS badge count displays the number of unread notifications within your application, taking the form of a red circle in the upper-right hand corner of the app icon. In recent years, badging has come to be an effective means for re-engaging app users.

How do I enable app icon Badges on my iPhone?

Check Settings appOn your iPhone or iPad, leave Things and go to the Settings app. Tap Notifications. Scroll down to find Things and tap it. Enable the toggle for Badges (if it's already on, toggle it off and back on).


2 Answers

Hi You need to register UIUserNotificationSettings like this

UIUserNotificationSettings* notificationSettings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound categories:nil];

[[UIApplication sharedApplication] registerUserNotificationSettings:notificationSettings];

[UIApplication sharedApplication].applicationIconBadgeNumber = 1;
like image 162
Uma Madhavi Avatar answered Sep 20 '22 13:09

Uma Madhavi


Registering for Notification Types in iOS

In iOS 8 and later, apps that use either local or remote notifications must register the types of notifications they intend to deliver. The system then gives the user the ability to limit the types of notifications your app displays. The system does not badge icons, display alert messages, or play alert sounds if any of these notification types are not enabled for your app, even if they are specified in the notification payload. Link: Docs

@property(nonatomic) NSInteger applicationIconBadgeNumber; // set to 0 to hide. default is 0. In iOS 8.0 and later, your application must register for user notifications using -[UIApplication registerUserNotificationSettings:] before being able to set the icon badge.

So I think you must register badges for change number notification.

like image 35
vien vu Avatar answered Sep 21 '22 13:09

vien vu