简体   繁体   English

在ios 9中设置应用程序徽章编号

[英]Set the application badge number in ios 9

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];

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;

Registering for Notification Types in iOS 在iOS中注册通知类型

In iOS 8 and later, apps that use either local or remote notifications must register the types of notifications they intend to deliver. 在iOS 8及更高版本中,使用本地或远程通知的应用程序必须注册他们打算提供的通知类型。 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; @property(nonatomic)NSInteger applicationIconBadgeNumber; // set to 0 to hide. //设置为0隐藏。 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. 默认值为0.在iOS 8.0及更高版本中,您的应用程序必须使用 - [UIApplication registerUserNotificationSettings:]注册用户通知,然后才能设置图标标记。

So I think you must register badges for change number notification. 所以我认为你必须为变更号码通知注册徽章。

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。

Set it in you Appdelegate.m File in didFinishLaunching method... didFinishLaunching方法中的Appdelegate.m文件中设置它...

application.applicationIconBadgeNumber = 5.

and change your current date to after 2 days and restart Your iPhone .. and test again. 并将当前日期更改为2天后重新启动iPhone ..然后再次测试。 It should be working fine. 它应该工作正常。

在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM