2016-04-27 64 views
1

安装ios9.3后我没有得到devicetoken,但之前在ios9.2.1中运行良好。没有得到devicetoken或没有在ios9.3中调用didfailRemotenotification

这里的代码(没有什么特别)

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

我也是在9.3.1得到这个同样的问题,你有没有发现这方面的任何解决方案或原因是什么? –

+0

Righnow我没有任何解决方案。 – SmarterSusheel

回答

1

如果使用beta版则可能会出现这个问题。检查Apple Forum;有些人对测试版本有同样的抱怨,因此可以在iOS的测试版中告知bug

+0

我没有使用测试版,甚至我安装了ios 9.3.1,并且发生了相同的问题 – SmarterSusheel

+0

尝试在ios 8或7等ios的另一个版本中运行。如果它工作,那么问题应该称为奇怪! – Lion

+0

雅我已经在9.2.1尝试过,它的工作完美。 – SmarterSusheel

0

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

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

我已经使用这种方法,但控制不进入此方法。 – SmarterSusheel

0

我得到了同样的问题。我发现这是因为[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)]; 
} 
相关问题