我在安装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)];
}
答案 0 :(得分:1)
如果您使用的是测试版,则可能会出现此问题。检查Apple Forum;有些人对测试版有同样的抱怨,因此可以在测试版iOS中告知bug
。
答案 1 :(得分:0)
尝试使用此方法,您将获得发生的错误。
-(void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
{
NSlog("application:didFailToRegisterForRemoteNotificationsWithError: %@", error)
}
答案 2 :(得分:0)
我遇到了同样的问题。我发现这是因为[application respondsToSelector:@selector(isRegisteredForRemoteNotifications)]
在上面的代码中返回了FALSE
。我不知道为什么会发生这种情况,因为{9.3}中也应该提供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)];
}