我正在尝试使用 Firebase 向我的应用程序发送后台推送通知。 iOS 正常显示通知,但 -application:didReceiveRemoteNotification:fetchCompletionHandler:
未在我的 AppDelegate
上调用。
当设备连接到调试器时,当设备收到通知时,我会收到以下日志消息。
2016-07-27 15:13:08.234: FIRMessaging receiving notification in invalid state 2
2016-07-27 15:13:08.234 MyApp[2513:1130209] Warning: Application delegate received call to -application:didReceiveRemoteNotification:fetchCompletionHandler: but the completion handler was never called.
在我看来,Firebase 正在调整 -application:didReceiveRemoteNotification:fetchCompletionHandler:
但未能调用我的实现,因为它认为应用程序处于无效状态,而事实并非如此。
通知负载也没有什么特别之处会导致问题。
{
gcm.message_id: 0:1469652824137045%3aef914a3aef914a,
objectId: 7,
aps: {
alert: "Your object has been updated"
content-available: 1
}
}
为什么 Firebase 说应用处于无效状态并且无法将通知转发到我的 AppDelegate
?
最佳答案
我认为您可能误解了错误 - 发生此错误是因为正在调用您应用的 didReceiveRemoteNotification
处理程序。
问题可能是在您的 didReceiveRemoteNotification
处理程序中,您需要确保使用正确的 UIBackgroundFetchResult
类型调用 completionHandler
。 (如果您使用的是 Swift,它可能看起来像 completionHandler(.NewData)
。)
当您向 iOS 发送远程通知时,这基本上就是您的应用让 iOS 知道它已经完成了您希望它完成的任何工作的方式。如果您不这样做,iOS 将对您的应用不满意,并可能在未来停止转发通知。
关于ios - Firebase SDK 不提供后台通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38623433/