码迷,mamicode.com
首页 > 移动开发 > 详细

iOS8设置应用图标红点的权限问题

时间:2014-11-21 23:09:16      阅读:322      评论:0      收藏:0      [点我收藏+]

标签:blog   io   ar   os   使用   sp   for   strong   on   

在ios8中,直接设置application badge value会出错

 1 [[UIApplication sharedApplication] setApplicationIconBadgeNumber:count]; 

曝出”Attempting to badge the application icon but haven‘t received permission from the user to badge the application“的错误。

  原因是因为在ios8中,设置应用的application badge value需要得到用户的许可。使用如下方法咨询用户是否许可应用设置application badge value

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

程序运行时,会弹出提示框给用户

 

 

iOS8中新增了通知授权后的回调:
– (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
问题解决
把所有
– (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions中的-[UIApplication setApplicationIconBadgeNumber:]
移到
– (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
回调中

iOS8设置应用图标红点的权限问题

标签:blog   io   ar   os   使用   sp   for   strong   on   

原文地址:http://www.cnblogs.com/daguo/p/4113895.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!