繁体   English   中英

在 ios9.3 中未获取 devicetoken 或未调用 didfailRemotenotification

[英]Not getting devicetoken or not called didfailRemotenotification in ios9.3

安装 ios9.3 后我没有得到设备令牌,但以前在 ios9.2.1 中运行良好。

这是代码(没什么特别的)

 if ([application respondsToSelector:@selector(isRegisteredForRemoteNotifications)]) {
    [application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
    [application registerForRemoteNotifications];
}
else {
    // iOS < 8 Notifications
    [application registerForRemoteNotificationTypes:
     (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound)];
}

如果您使用的是测试版,则可能会出现此问题。 查看苹果论坛 有些人对测试版有同样的抱怨,所以可以告诉 iOS 测试版中的bug

试试这个方法,你会得到发生了什么错误。

-(void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
{
NSlog("application:didFailToRegisterForRemoteNotificationsWithError: %@", error)
 }

我遇到了同样的问题。 我发现是因为[application respondsToSelector:@selector(isRegisteredForRemoteNotifications)]在上面的代码中返回了FALSE 我不知道为什么会发生这种情况,因为isRegisteredForRemoteNotifications也应该在 iOS 9.3.1 中可用。

但无论如何,我只是将 if case 更改为([[[UIDevice currentDevice] systemVersion] compare:@"8.0" options:NSNumericSearch] != NSOrderedAscending)以检查 iOS 版本,它现在可以正常工作。

代码现在变成

if (([[[UIDevice currentDevice] systemVersion] compare:@"8.0" options:NSNumericSearch] != NSOrderedAscending)) {
    // iOS 8 Notifications
    [[UIApplication sharedApplication] registerUserNotificationSettings:
     [UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge)
                                       categories:nil]
     ];
    [[UIApplication sharedApplication] registerForRemoteNotifications];
} else {
    // iOS < 8 Notifications
    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound)];
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM