无法接收 iOS 的 FCM 推送通知

Can't receive FCM Push Notifications for iOS

我正在尝试使用 Firebase 云消息传递 (FCM) SDK 向 iOS 设备发送推送通知。我创建了一个非常简单的应用程序,它有一个空的 ViewController 和一个由 quick start iOS project.

中提供的复制的 AppDelegate

我遵循了 guide 中提供的所有说明:

使用 pod 安装 SDK,这是我的 podFile:

# Uncomment the next line to define a global platform for your project
# platform :ios, '9.0'

pod 'Firebase/Core'
pod 'Firebase/Messaging'

target 'fcmPushTest' do
# Comment the next line if you're not using Swift and don't want to use 
dynamic frameworks
use_frameworks!

# Pods for fcmPushTest

end

当应用程序启动时,它会正确 returns 一个 FCM 令牌。然后我在 FCM 推送通知控制台中使用此令牌以发送消息但没有任何反应:即使控制台显示消息已 "completed" 也未收到通知

正在尝试使用 curl 发送通知

curl -X POST --header "Authorization: key=<API_ACCESS_KEY>" \
--Header "Content-Type: application/json" \
https://fcm.googleapis.com/fcm/send \
-d "{\"to\":\"<YOUR_DEVICE_ID_TOKEN>\",\"notification\":{\"body\":\"Yellow\"},\"priority\":10}"

我得到以下响应:

{"multicast_id":7144776975498650143,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:1510221288971805%7fe9e2a37fe9e2a3"}]}

由于成功等于 1,我想一切正常,但我仍然没有收到通知。

我用谷歌搜索了问题的可能原因,但似乎 Firebase 消息传递库最近已更改(pod 说我使用的是 FirebaseMessaging 2.0.3 版本)所以我找不到合适的解决方案。

问题是我忘记在 "Capabilities" 选项卡的 "Background Modes" 中添加 "Remote notification"。现在一切正常。