because in IOS8, if you want to set applicationIconBadgeNumber, you need user authorization. In IOS8, you need to add the following code:
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeBadge categories:nil]; [[UIApplication sharedApplication] registerUserNotificationSettings:settings]; UIApplication *app = [UIApplication sharedApplication]; // The number in the upper right corner of the application app.applicationIconBadgeNumber = 0;
However, if these two sentences are run in the IOS7 system, an error will be reported, so you need to judge the IOS version first. The complete code is as follows:
float version = [[[UIDevice currentDevice] systemVersion] floatValue]; if (version >= 8.0) { UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeBadge categories:nil]; [[UIApplication sharedApplication] registerUserNotificationSettings:settings]; } UIApplication *app = [UIApplication sharedApplication]; // The number in the upper right corner of the application app.applicationIconBadgeNumber = 0;
If it is a registration message push, you need to write:
float version = [[[UIDevice currentDevice] systemVersion] floatValue]; if (version >= 8.0) { UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeBadge categories:nil]; [[UIApplication sharedApplication] registerUserNotificationSettings:settings]; [application registerForRemoteNotifications]; } UIApplication *app = [UIApplication sharedApplication]; // The number in the upper right corner of the application app.applicationIconBadgeNumber = 0;