@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.
发现8.0以后,要先写-[UIApplication registerUserNotificationSettings:]这个方法
于是:
[[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeBadge categories:nil]];
[UIApplication sharedApplication].applicationIconBadgeNumber = [responseObject[@"status"] intValue];
应用程序进入后台默认处于休眠状态,这样就无法及时读取未读消息数,那怎么办呢?
在后台开启任务让程序时刻保持运行状态:(能维持运行的时间是不确定的,
时间: 2024-11-13 10:38:57