Set the application badge number in ios 9

Nazik picture Nazik · Oct 26, 2015 · Viewed 29.9k times · Source

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];

Answer

Uma Madhavi picture Uma Madhavi · Oct 26, 2015

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;