Summary
Setting Applicationiconbadgenumber in IOS7 is not a problem, but setting applicationiconbadgenumber directly in IOS8 will cause an error
Because you want to set up applicationiconbadgenumber in IOS8, you need the user's authorization, in IOS8, you need to add the following code:
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeBadge categories:nil];[[UIApplication sharedApplication] registerUserNotificationSettings:settings];
However, if the two sentences are running in the IOS7 system, then the error will be, so you need to first determine the iOS version, 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];}
If you are registering a message push, you need to write this:
float version = [[[UIDevice currentDevice] systemVersion] floatValue];if (version >= 8.0) { UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeBadge categories:nil]; [[UIApplication sharedApplication] registerUserNotificationSettings:settings]; [application registerForRemoteNotifications];}
Thanks for sharing
IOS Development-ios 8 Set up applicationiconbadgenumber and message push