ios 在ios 9中设置应用徽章编号
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/33339782/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Set the application badge number in ios 9
提问by Azik Abdullah
I'd used
我用过
[UIApplication sharedApplication].applicationIconBadgeNumber = 5;
for setting application badge number. It's not working in ios 9 alone.
用于设置应用程序徽章编号。它不能单独在 ios 9 中工作。
Can anyone suggest why?
谁能建议为什么?
I tried,
我试过,
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:5];
回答by Uma Madhavi
Hi You need to register UIUserNotificationSettings like this
嗨,您需要像这样注册 UIUserNotificationSettings
UIUserNotificationSettings* notificationSettings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:notificationSettings];
[UIApplication sharedApplication].applicationIconBadgeNumber = 1;
回答by vien vu
Registering for Notification Types in iOS
In iOS 8 and later, apps that use either local or remote notifications must register the types of notifications they intend to deliver. The system then gives the user the ability to limit the types of notifications your app displays. The system does not badge icons, display alert messages, or play alert sounds if any of these notification types are not enabled for your app, even if they are specified in the notification payload. Link: Docs
@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.
在 iOS 中注册通知类型
在 iOS 8 及更高版本中,使用本地或远程通知的应用程序必须注册它们打算传递的通知类型。然后,系统使用户能够限制您的应用程序显示的通知类型。如果您的应用程序未启用这些通知类型中的任何一种,即使它们在通知负载中指定,系统也不会标记图标、显示警报消息或播放警报声音。链接:文档
@property(nonatomic) NSInteger applicationIconBadgeNumber; // 设置为 0 以隐藏。默认值为 0。在 iOS 8.0 及更高版本中,您的应用程序必须使用 -[UIApplication registerUserNotificationSettings:] 注册用户通知,然后才能设置图标徽章。
So I think you must register badges for change number notification.
因此,我认为您必须为更改号码通知注册徽章。
回答by O.C.
It works perfectly like this:
它的工作原理是这样的:
[UIApplication sharedApplication].applicationIconBadgeNumber = 10;
I tried in Xcode 7.2, iOS 9.2, iPhone 6s Plus.
我在 Xcode 7.2、iOS 9.2、iPhone 6s Plus 中尝试过。
回答by Mehul
Set it in you Appdelegate.m
File in didFinishLaunching
method...
将它设置在你的Appdelegate.m
文件中didFinishLaunching
方法...
application.applicationIconBadgeNumber = 5.
application.applicationIconBadgeNumber = 5.
and change your current date to after 2 days and restart Your iPhone
.. and test again. It should be working fine.
并将您的当前日期更改为 2 天后并重新启动您的iPhone
.. 并再次测试。它应该工作正常。