ios7和ios8设置应用程序右上角数字

IOS7:

UIApplication *app = [UIApplication sharedApplication];
//应用程序右上角数字
app.applicationIconBadgeNumber =99;
上面的代码可以搞定

IOS8:

如果只用上边的代码会抛错:
Attempting to badge the application icon but haven't received permission from the user to badge the…
原因是因为在ios8中,设置应用的application badge value需要得到用户的许可,来提高用户体验。
使用如下方法咨询用户是否许可应用设置application badge value:

UIUserNotificationSettings *settings = [UIUserNotificationSettingssettingsForTypes:UIUserNotificationTypeBadge categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];

UIApplication*app = [UIApplicationsharedApplication];
//应用程序右上角数字
app.applicationIconBadgeNumber=0;

你可能感兴趣的:(ios7和ios8设置应用程序右上角数字)