curl 发送的 Firebase 云消息传递警报未明显出现在 iOS 台设备上

curl sent Firebase Cloud Messaging alert not visibly appearing on iOS device

我正在尝试让 Firebase 云消息传递 iOS 警报从我的服务器发送到 FCM 以显示在我的 iOS 设备上。

如果我从 FCM 控制台发送消息:

https://console.firebase.google.com/project/your-awesome-project/notification

和 FCM 示例应用程序:

https://github.com/firebase/quickstart-ios

已关闭或在后台,警报显示得很漂亮,

如果它在前台,我会在 iOS 控制台中看到:

{
    aps =     {
        alert = "HEY YO";
    };
    "gcm.message_id" = "0:123456789_blah_blah";
    "gcm.n.e" = 1;
    "google.c.a.c_id" = 123XXXXXXXX789;
    "google.c.a.e" = 1;
    "google.c.a.ts" = 123XXX789;
    "google.c.a.udt" = 0;
}

...但如果我尝试这样做:

curl -X POST 
--header "Authorization: key=<server key>" 
--header "Content-Type: application/json" 
https://fcm.googleapis.com/fcm/send
-d "{\"to\":\"<device registration id>\",\"notification\":{\"body\": \"HEY YO\"}}"

...它永远不会显示为警报,无论 FCM 示例应用程序是在前台、后台还是完全关闭。

它确实显示在 iOS 控制台中,但参数较少:

{
    aps =     {
        alert = "HEY YO";
    };
    "gcm.message_id" = "0:123456789_blah_blah";
}

是否可以使用 curl 触发在我的 iOS 设备上显示为警报的 Firebase 云消息传递通知?

回答 [感谢 2 亚瑟!]:

只需添加:\"priority\":\"high\"

像这样:

curl -X POST 
--header "Authorization: key=<server key>" 
--header "Content-Type: application/json" 
https://fcm.googleapis.com/fcm/send
-d "{\"to\":\"<device registration id>\",\"priority\":\"high\",\"notification\":{\"body\": \"HEY YO\"}}"

...我看到一个漂亮的警报通知!!!

是的!可能是您发送的消息未通过 APNs 中继到设备。在 curl 数据中添加优先级字段并将其设置为高在这种情况下应该会有所帮助。

但是请注意,仅当需要立即与用户交互时才建议将 high priority 用于发布版本,例如聊天消息。