0

In my app I need to set badge onto the app icon and set numbers for this badge. The problem is that I need to register user notification settings like this:

if ([[UIApplication sharedApplication] respondsToSelector:@selector(registerUserNotificationSettings:)])
{
    [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeBadge categories:nil]];
}

in order to make it work on iOS8. If I run this code then on start system presents an alert to the user which says something like:ApplicationName would like to send you notifications. Notifications may include bla la bla. It's the standard one, I'm sure you've seen it many times. Just because I registered notification settings the system thinks my app is going to post some notifications. But it's not! I don't want to post notifications. All I wanna do is to set badge onto the icon and a number onto this badge. Is there any possibility to achieve this on iOS 8 without registering user notifications or registering but not showing that system alert? Any ideas, guys?

Andrey Chernukha
  • 21,488
  • 17
  • 97
  • 161
  • It's part of the permissions. If you want to set the badge, you need to ask the user for permission to do so. No workaround for this. – n00bProgrammer Jan 20 '15 at 10:26
  • I hear you man. It's unfortunate that users have to now see the same "scary" notifications permission request as they would for full blown push notifications request just to update the badge count. You might as well just implement push notifications so you have the option to send different types of notifications in the future. Your users will see the same request. Blame all the programmers before you who abused notifications. :) – jeffjv Jul 07 '15 at 21:30

1 Answers1

3

The documentation is explicit on that point, on iOS8 and later, you have to register for user notifications :

@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.

adhumi
  • 475
  • 3
  • 15