iOS 8.更改应用程序徽章号码,没有任何通知

在我的应用程序中,我需要将徽章设置到应用程序图标上,并为此徽章设置数字。 问题是我需要像这样注册用户通知设置:

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

为了使它在iOS8上工作。 如果我运行这个代码,然后在启动系统提出一个警告给用户这样说: ApplicationName would like to send you notifications. Notifications may include bla la bla ApplicationName would like to send you notifications. Notifications may include bla la bla 。 这是标准的,我相信你已经看过很多次了。 只是因为我注册通知设置系统认为我的应用程序将发布一些通知。 但不是! 我不想发布通知。 我想要做的就是把徽章放在图标上,并在这个徽章上加一个数字。 有没有可能实现这一点在iOS 8上没有注册用户通知或注册,但没有显示系统警报? 任何想法,家伙?

该文档在这一点上是明确的,在iOS8和更高版本中,您必须注册用户通知:

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