因为在IOS8中要想设置applicationIconBadgeNumber,需要用户的授权,在IOS8中,需要加上下面的代码:
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeBadge categories:nil]; [[UIApplication sharedApplication] registerUserNotificationSettings:settings];
但是这两句如果是在IOS7的系统中运行的话就会报错,所以需要先判断IOS的版本,完整代码如下:
float version = [[[UIDevice currentDevice] systemVersion] floatValue]; if (version >= 8.0) { UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeBadge categories:nil]; [[UIApplication sharedApplication] registerUserNotificationSettings:settings]; }
时间: 2024-12-06 11:44:23