首页 文章

curl发送的Firebase Cloud 消息传递警报在iOS设备上无法显示

提问于
浏览
9

我正在尝试将从我的服务器发送到FCM的Firebase Cloud Messaging iOS警报显示在我的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";
}

Is it possible to use curl to fire off Firebase Cloud Messaging notifications that appear as alerts on my iOS device?

ANSWER [thanx 2 Arthur!] :

只需添加: \"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\"}}"

......我看到一个美丽的警报通知!

1 回答

  • 10

    是!可能是您正在发送的消息未被APN中继到设备 . 在这种情况下,添加优先级字段并在curl数据中将其设置为高可能会有所帮助 .

    但请注意,仅当与预期的用户交互时,建议使用high priority用于发布版本,例如聊天消息 .

相关问题