【问题标题】:curl sent Firebase Cloud Messaging alert not visibly appearing on iOS devicecurl 发送的 Firebase 云消息警报在 iOS 设备上没有明显显示
【发布时间】:2016-10-30 04:00:54
【问题描述】:

我正在尝试让 Firebase Cloud Messaging 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 云消息传递通知?

回答 [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\"}}"

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

【问题讨论】:

    标签: ios curl google-cloud-messaging apple-push-notifications firebase-cloud-messaging


    【解决方案1】:

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

    但请注意,仅在需要即时用户交互(例如聊天消息)时,才建议在发布版本中使用 high priority

    【讨论】:

    • 谢谢,这很令人沮丧。我试图将优先级明确设置为“正常”,但它也不起作用。可能是我正在使用开发 APNS 证书,这可能不是生产中的问题。
    • 好的,谢谢!这是一个巨大的帮助。您知道是否有任何方法仍然可以仅使用“数据”而不是 Json 中的“通知”来发送这些消息?我只想在后台触发某些东西,而不是看到通知。如果应用关闭,我仍然会看到通知中的正文。
    • 好的,在这里找到了我在 iOS 上静默通知的答案,仅供参考:stackoverflow.com/questions/37570200/…
    猜你喜欢
    • 2020-10-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-16
    • 2021-04-06
    • 1970-01-01
    相关资源
    最近更新 更多