Firebase背景推送通知不起作用&没有重新连接到FCM确实变得活跃

时间:2017-03-08 19:30:54

标签: ios swift firebase apple-push-notifications firebase-cloud-messaging

我使用示例应用代理代码行来代替Firebase example app,但我仍然无法在后台接收推送通知。如果我重新启动应用程序,我会在前台看到它们。

我很确定我在我的应用程序中配置了所有内容,而我能找到的唯一异常是,当它进入后台时,它会与FCM断开连接(显然是设计上的),但当我将应用程序带入前景它没有重新连接,因为令牌是nil(它在第一个守卫上挽救)。

func connectToFcm() {
    // Won't connect since there is no token
    guard FIRInstanceID.instanceID().token() != nil else {
        return;
    }

    // Disconnect previous FCM connection if it exists.
    FIRMessaging.messaging().disconnect()

    FIRMessaging.messaging().connect { (error) in
        if error != nil {
            print("Unable to connect with FCM. \(error)")
        } else {
            print("Connected to FCM.")
        }
    }
}

这很奇怪,因为在启动应用程序时设置了实例令牌,所以我不确定它为什么会停止工作。

这可能不是我在后台看到推文的原因,但我认为解决这个问题可能是开始深入了解。

0 个答案:

没有答案