App右上角数字

IOS7:

  1. UIApplication *app = [UIApplication sharedApplication];
  2. // 应用程序右上角数字
  3. app.applicationIconBadgeNumber = 99;

上面的代码可以搞定

IOS8:

iOS8中设置application badge value 会抛错: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 = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeBadge categories:nil];

[[UIApplication sharedApplication] registerUserNotificationSettings:settings];

在这之前要判断系统是否为iOS8的系统,否则8之前的系统会报错。

  1. UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeBadge categories:nil];
  2. [[UIApplication sharedApplication] registerUserNotificationSettings:settings];
  3. UIApplication *app = [UIApplication sharedApplication];
  4. // 应用程序右上角数字
  5. app.applicationIconBadgeNumber = 0;

注意:清除数字请将数字设置为 0

上一篇:初识Lucene.net


下一篇:VMware Ubuntu安装具体过程