Set the application badge number in ios 9

2019-02-08 00:57发布

I'd used

[UIApplication sharedApplication].applicationIconBadgeNumber = 5;

for setting application badge number. It's not working in ios 9 alone.

Can anyone suggest why?

I tried,

[[UIApplication sharedApplication] setApplicationIconBadgeNumber:5];

标签: ios ios9 badge
4条回答
太酷不给撩
2楼-- · 2019-02-08 01:08

Hi You need to register UIUserNotificationSettings like this

UIUserNotificationSettings* notificationSettings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound categories:nil];

[[UIApplication sharedApplication] registerUserNotificationSettings:notificationSettings];

[UIApplication sharedApplication].applicationIconBadgeNumber = 1;
查看更多
我欲成王,谁敢阻挡
3楼-- · 2019-02-08 01:22

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.

So I think you must register badges for change number notification.

查看更多
虎瘦雄心在
4楼-- · 2019-02-08 01:27

Set it in you Appdelegate.m File in didFinishLaunching method...

application.applicationIconBadgeNumber = 5.

and change your current date to after 2 days and restart Your iPhone.. and test again. It should be working fine.

enter image description here

查看更多
一夜七次
5楼-- · 2019-02-08 01:29

It works perfectly like this:

[UIApplication sharedApplication].applicationIconBadgeNumber = 10;

I tried in Xcode 7.2, iOS 9.2, iPhone 6s Plus.

查看更多
登录 后发表回答