首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在ios9.3中未获取设备令牌或未调用didfailRemotenotification

在ios9.3中未获取设备令牌或未调用didfailRemotenotification
EN

Stack Overflow用户
提问于 2016-04-27 20:03:13
回答 3查看 444关注 0票数 1

在安装了ios9.3之后,我没有得到devicetoken,但之前在ios9.2.1中工作得很好。

下面是代码(没什么特别的)

代码语言:javascript
复制
 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)];
}
EN

回答 3

Stack Overflow用户

发布于 2016-04-27 20:09:29

如果您使用的是测试版,则可能会出现此问题。检查Apple Forum;有些人对测试版也有同样的抱怨,所以它可以在测试版的iOS中告诉bug

票数 1
EN

Stack Overflow用户

发布于 2016-04-27 20:48:41

尝试这个方法,你会知道发生了什么错误。

代码语言:javascript
复制
-(void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
{
NSlog("application:didFailToRegisterForRemoteNotificationsWithError: %@", error)
 }
票数 0
EN

Stack Overflow用户

发布于 2016-05-14 08:05:20

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

但不管怎样,我只是将if的大小写改为([[[UIDevice currentDevice] systemVersion] compare:@"8.0" options:NSNumericSearch] != NSOrderedAscending)来检查iOS版本,它现在可以正常工作了。

代码现在变成了

代码语言:javascript
复制
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)];
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36889248

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档