iOS 8.更改应用程序徽章编号,无任何通知

时间:2015-01-20 10:22:44

标签: ios cocoa-touch ios8 notifications badge

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

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。它是标准的,我相信你已经多次见过它了。仅仅因为我注册了通知设置,系统认为我的应用程序将发布一些通知。但事实并非如此!我不想发布通知。我想做的就是在徽章上设置徽章和一个数字。是否有可能在iOS 8上实现此功能而无需注册用户通知或注册但未显示系统警报?任何想法,伙计们?

1 个答案:

答案 0 :(得分:3)

关于这一点,文档是明确的,在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.