iOS8中设置App红点提示没有权限的问题

问题描述:在iOS8中调用-[UIApplication setApplicationIconBadgeNumber:]会出现如下没有权限的提示:
Attempting to badge the application icon but haven't received permission from the user to badge the application
问题分析
用如下方法注册通知权限后,App会弹出一个框进行确认。在确认之前或者被否决,都是没有权限设置红点的。
UIUserNotificationSettings* notificationSettings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:notificationSettings];
iOS8中新增了通知授权后的回调:
- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
问题解决
把所有
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions中的-[UIApplication setApplicationIconBadgeNumber:]
移到
- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
回调中

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注