iOS 8. Change app badge number without any notifications

回眸只為那壹抹淺笑 提交于 2020-01-16 10:49:08

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/28042898/ios-8-change-app-badge-number-without-any-notifications

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!