仅在收到令牌更改

时间:2017-07-18 11:18:11

标签: ios firebase firebase-cloud-messaging

编辑:使用新信息更新问题。

因此,有很多关于没有收到Firebase通知的问题,但我没有找到一个非常类似的问题。

我最近使用旧的p12 APNs证书切换到了光荣的新p8,并将其上传到我在Firebase v4.0.0上的所有项目中。

我所看到的是,当我对我的任何项目进行全新安装时,我可以发送&接收推送通知很好。但过了一段时间后,令牌发生了变化 - 它只是停止工作 - Firebase说“消息已成功发送”,但没有收到任何消息。

很奇怪 - 我的应用仍会收到上一个Firebase令牌的推送通知,而Firebase报告的新推文无效。

按照Debugging Firebase Cloud Messaging on iOS的建议,我很高兴地调试了早晨:

  1. 我的Postman firebase尝试是否有任何错误消息?不,成功:每次
  2. 我是在后台推出app,前台还是不推?的既不即可。
  3. 我的AppDelegate远程通知注册尝试是否成功运行? 即可。
  4. 我可以使用新的.p8文件直接通过APN发送消息吗? (感谢this)。当我通过APN直接发送消息时收到消息就好了!
  5. 在Firebase控制台中,如果我向项目中的所有设备发送消息,我会收到所有设备的消息。但是,如果我尝试通过其FCM令牌将其限制在我的调试设备上,我什么也得不到。

    所以有一个最后一个链接只是不起作用 - 似乎完美适用于新安装,然后在一段时间后轰炸 - FCM到APNs链接。但是我该怎么调试呢?

1 个答案:

答案 0 :(得分:1)

这里在

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

...
NotificationCenter.default.addObserver(self,
                                               selector: #selector(self.tokenRefreshNotification),
                                               name: .firInstanceIDTokenRefresh,
                                               object: nil)
        return true
}

func tokenRefreshNotification(_ notification: Notification) {
        if let refreshedToken = FIRInstanceID.instanceID().token() {
            print("InstanceID token: \(refreshedToken)")
            // Here you get the refreshed token
            // here you can connect to fcm and do subscribe to notifications
        }
    }

希望它能解决问题。