在安装了ios9.3之后,我没有得到devicetoken,但之前在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)];
}发布于 2016-04-27 20:09:29
如果您使用的是测试版,则可能会出现此问题。检查Apple Forum;有些人对测试版也有同样的抱怨,所以它可以在测试版的iOS中告诉bug。
发布于 2016-04-27 20:48:41
尝试这个方法,你会知道发生了什么错误。
-(void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
{
NSlog("application:didFailToRegisterForRemoteNotificationsWithError: %@", error)
}发布于 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版本,它现在可以正常工作了。
代码现在变成了
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)];
}https://stackoverflow.com/questions/36889248
复制相似问题