didRegisterForRemoteNotificationsWithDeviceToken永远不会调用特定的设备

首先,我在iPhone 6 Plus / iOS 8.1上,我已经尝试了一切: 为什么没有调用RegisterForRemoteNotificationsWithDeviceToken

仍然无济于事。 总结:

  • 我已经检查了我的包标识符与configuration文件/开发门户中的包标识符相匹配
  • 我已经创build了一个新的开发推APNS证书
  • 我已经创build了一个新的开发证书
  • 我为该开发证书创build了一个新的configuration文件
  • 我已经下载了证书和configuration文件,显然,双击它们进行安装
  • 我已经validationDeveloper Portal上的所有内容都正确:所有证书和configuration文件都有效,推送启用并使用我的新APNS证书进行configuration
  • 我已经将我的新APNS证书上传到Parse(这一步无关紧要,但无论如何),因为我正在使用Parse分析我的后端
  • 我确定我在Xcode上使用正确的证书/configuration文件对来进行密码设置
  • 我检查了通知设置,以防我的应用程序不允许接收推送,它不在那里
  • 我试过手动设置date到明天,并尝试重新安装应用程序
  • 我已经从我的设备中删除了该应用程序
  • 我从我的设备中删除了任何相关的configuration文件
  • 我已经多次重启我的设备

application:didFinishLaunchingWithOptions:我打电话给:

 if([application respondsToSelector:@selector(registerUserNotificationSettings:)]){ //iOS 8+ [application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]]; }else{ //pre-iOS 8 [[UIApplication sharedApplication] registerForRemoteNotificationTypes: (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)]; } 

application:didRegisterUserNotificationSettings:我打电话给:

 [application registerForRemoteNotifications]; 

我已经检查了一个断点,它会被调用。 我也实现了两种方法:

application:didRegisterForRemoteNotificationsWithDeviceToken:

application:didFailToRegisterForRemoteNotificationsWithError:

但是,他们都没有被调用。 不是一个错误,没有。 在控制台也没有错误。 (我今天早些时候有一个关于权利的问题,但是创build新的证书/configuration文件解决了这个问题)

可能是什么问题?

更新:这是一些东西。 在application:didRegisterUserNotificationSettings:我已经检查了通知设置,这里是我得到的:

 (lldb) po notificationSettings <UIUserNotificationSettings: 0x170031cc0; types: (none);> 

更新2:我再次检查通知,发现现在我的应用程序已添加到设置中的通知,它已启用,授予权限。 但是,处理程序仍然没有被调用。 types是没有的。 我99%肯定这是与问题有关。

更新3:我已经在另一台设备(iPod touch,iOS 8.1)上进行了testing,在这里我没有任何问题。 它立即用它的标记调用application:didRegisterForRemoteNotificationsWithDeviceToken:方法。 这个问题是特定于我的iPhone。

我得到了类似的问题,代码已经实施,工作正常。 突然之间,经过一番调整,它不再工作了。

在设备上运行的场景是:

  • didFinishLaunchingWithOptions上调用registerForRemoteNotifications
  • didRegisterForRemoteNotificationsWithDeviceToken将不会调用
  • 也没有didFailToRegisterForRemoteNotificationsWithError不会调用。

我尝试了一切,几乎重置所有的推送configuration和证书和供应configuration文件等。所有最后版本的设备工作,但是当我安装新版本,只是不再工作。

为了解决这个问题,我只是这样做了:

  1. 去了目标的能力;
  2. closures 推送通知 ;
  3. 在设备上构build运行应用程序并等待;
  4. 停止运行应用程序;
  5. 再次打开推送通知
  6. 在设备上构build运行应用程序;
  7. 就像魔法一样,它又起作用了

经过6个小时与Xcode打架,这是我的解决scheme,没有任何解释。

我希望这可以帮助别人。

我被要求在iOS9下的客户端应用程序上debugging类似的行为。

事实certificate,该应用程序正在调用appDelegate的registerUserNotificationSettings和registerForRemoteNotifications。

但是,在后续的permissionsViewController中,这也是第二次。

如果用户拒绝了appDelegate引起的请求,那么在用户看到允许它的基本原理(来自permissionsViewController的第二个调用)后,后续尝试允许通知被设置为与appDelegate调用相同的types。

删除最初的appDelegate调用,只有权限viewViewController调用目前解决了这一点。

另一件要检查的是APNS的系统状态,位于Apple https://developer.apple.com/system-status/

我在想,为什么我不能在APNS系统“遇到问题”的时候注册我的设备。

尝试使用这个:(运行良好),抱歉堆栈似乎没有格式化好

  - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { if ([application respondsToSelector:@selector(registerUserNotificationSettings:)]) { NSLog(@"iOS 8 Requesting permission for push notifications..."); // iOS 8 UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes: UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound categories:nil]; [UIApplication.sharedApplication registerUserNotificationSettings:settings]; [[UIApplication sharedApplication] registerForRemoteNotifications]; } else { NSLog(@"iOS 7 Registering device for push notifications..."); // iOS 7 and earlier [UIApplication.sharedApplication registerForRemoteNotificationTypes: UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound]; } return YES; } - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo { UIApplicationState state = [application applicationState]; if (state == UIApplicationStateActive) { NSLog(@"received a notification while active..."); } else if ( application.applicationState == UIApplicationStateInactive || application.applicationState == UIApplicationStateBackground ) { //opened from a push notification when the app was on background NSLog(@"i received a notification..."); NSLog(@"Message: %@",[[userInfo objectForKey:@"aps"] objectForKey:@"alert"]); NSLog(@"whole data: %@",userInfo); } } - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { self.token = [[deviceToken description] stringByTrimmingCharactersInSet: [NSCharacterSet characterSetWithCharactersInString:@"<>"]]; self.token = [self.token stringByReplacingOccurrencesOfString:@" " withString:@""]; [[NSUserDefaults standardUserDefaults] setObject:self.token forKey:@"deviceToken"]; [[NSUserDefaults standardUserDefaults] synchronize]; NSLog(@"-->> TOKEN:%@",self.token); } - (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings{ NSLog(@"Registering device for push notifications..."); // iOS 8 [application registerForRemoteNotifications]; } - (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forRemoteNotification:(NSDictionary *)notification completionHandler:(void(^)())completionHandler { NSLog(@"Received push notification: %@, identifier: %@", notification, identifier); // iOS 8 s completionHandler(); } - (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error { // Respond to any push notification registration errors here. NSLog(@"Failed to get token, error: %@", error); }