ios - didRegisterForRemoteNotificationsWithDeviceToken 从未在特定设备上调用

标签 ios xcode push-notification apple-push-notifications provisioning-profile

<分区>

首先,我使用的是 iPhone 6 Plus/iOS 8.1,我已经尝试了这里的所有方法:why didRegisterForRemoteNotificationsWithDeviceToken is not called

还是不行。总结:

  • 我已检查我的包标识符是否与配置文件/开发门户中的标识符相匹配
  • 我已经创建了一个新的开发推送 APNS 证书
  • 我已经创建了一个新的开发证书
  • 我已经为那个开发证书创建了一个新的配置文件
  • 我已经下载了证书和配置文件,显然,双击它们进行安装
  • 我已验证 Developer Portal 上的一切正常:所有证书和配置文件均有效,已启用推送并使用我的新 APNS 证书进行了配置
  • 我已将我的新 APNS 证书上传到 Parse(这一步无关紧要,但无论如何),因为我正在为我的后端使用 Parse
  • 我已确保我在 Xcode 上使用正确的证书/配置文件对进行代码签名
  • 我已经检查了通知设置,以防我的应用无法接收推送,但它不存在
  • 我尝试手动将日期设置为明天并尝试重新安装应用
  • 我已经从我的设备上删除了该应用
  • 我已经从我的设备中删除了所有相关的配置文件
  • 我已多次重启我的设备

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];

我用断点检查了它,它确实被调用了。我还实现了两种方法:

应用程序:didRegisterForRemoteNotificationsWithDeviceToken:

应用程序:didFailToRegisterForRemoteNotificationsWithError:

但是,它们都没有被调用。不是错误,没什么。控制台也没有错误。 (我今天早些时候遇到过关于权利的问题,但创建新的证书/配置文件解决了这个问题)

可能是什么问题?

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

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

更新 2: 我再次检查了通知,发现现在我的应用程序已添加到“设置”中的通知中,它已启用,并获得了权限。但是,处理程序仍然没有被调用。 类型没有。我 99% 确定它与问题有关。

更新 3:我已经在另一台设备(iPod touch、iOS 8.1)上进行了测试,没有遇到任何问题。它立即使用其 token 调用 application:didRegisterForRemoteNotificationsWithDeviceToken: 方法。这个问题是我的 iPhone 特有的。

最佳答案

我遇到了类似的问题,代码已经实现并且运行良好。 突然,经过一些调整,它不再工作了。

在设备上运行的场景是:

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

我尝试了一切,几乎重置了所有推送配置和证书以及配置文件等。 使用最新版本的所有设备都可以工作,但是当我安装新版本时,就不再工作了。

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

  1. 了解目标能力;
  2. 关闭推送通知
  3. 构建并在设备上运行应用并等待;
  4. 停止运行该应用;
  5. 再次打开推送通知
  6. 构建并在设备上运行应用;
  7. 就像变魔术一样,它再次奏效了

在与 Xcode 斗争 6 小时后,这就是我的解决方案,没有任何解释。

我希望这对某人有所帮助。

关于ios - didRegisterForRemoteNotificationsWithDeviceToken 从未在特定设备上调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26817810/

相关文章:

iOS CocoaPod 警告 - "Google has been deprecated"- 使用 pod 'Google/SignIn' 时

xcode - 新解析强制 "optional",如何查询 PFUser?

iphone - 计算两个CGPoint的外点

Javascript Service Worker - 如何在浏览器关闭时触发事件

objective-c - 有没有办法访问 iTunes 库来设置闹钟铃声?

ios - 带有 xcode 8 的 Alamofire 2.0

ios - 委派设置后未出现导航栏

xcode - iOS8.0 的 CompileSwift 状态为 "the current deployment target does not support automated __weak references"

c# - 将 FCM 与 Asp.net web api 2 结合使用

ios - 如何在 iOS 10 中为推送通知设置角标(Badge)计数?