【问题标题】:FCM 'condition' field does not workFCM“条件”字段不起作用
【发布时间】:2017-11-23 17:05:32
【问题描述】:

我无法使用 condition 字段发送要发送到多个主题的 FCM 消息。出于某种原因,即使 FCM 没有发送我的任何错误,我的设备在使用此字段时也不会收到消息。

当我发送这个时:

{
"to": "/topics/topic1",
"data": {
    "message": "test"
    }
}

消息已收到,但我没有收到任何内容:

{
"condition": "'topic1' in topics",
"data": {
    "message": "test"
    }
}

甚至认为两条消息都使用相同的主题名称,并且两条消息都从 Firebase 返回成功消息。

【问题讨论】:

  • 您找到解决方案了吗?如果有,请分享。
  • 很遗憾,我没有。我不得不用其他方式做到这一点。祝你好运。

标签: firebase firebase-cloud-messaging


【解决方案1】:

您必须为您的设备订阅您的主题,您可以为订阅提供休息服务。 Reference 当您想发送消息时,您可以提供标题和正文

例子:

{
  "message":{
        "condition": "'topic1' in topics",
         "data": {
           "message": "test"
       },
   "notification" : {
         "body" : "This is an FCM notification message!",
         "title" : "FCM Message",
      }
   }
}

带有建模响应reference 主题 HTTP POST 请求

Send to a single topic:

https://fcm.googleapis.com/fcm/send
Content-Type:application/json
Authorization:key=AIzaSyZ-1u...0GBYzPu7Udno5aA
{
  "to": "/topics/foo-bar",
  "data": {
    "message": "This is a Firebase Cloud Messaging Topic Message!",
   }
}
Send to devices subscribed to topics "dogs" or "cats":

https://fcm.googleapis.com/fcm/send
Content-Type:application/json
Authorization:key=AIzaSyZ-1u...0GBYzPu7Udno5aA
{
  "condition": "'dogs' in topics || 'cats' in topics",
  "data": {
    "message": "This is a Firebase Cloud Messaging Topic Message!",
   }
}
Topic HTTP response

//Success example:
{
  "message_id": "1023456"
}

//failure example:
{
  "error": "TopicsMessageRateExceeded"
}

我使用 java RestTemplate 并交换响应。

【讨论】:

  • 我的设备已经订阅了该主题,否则在第一种情况下我不会收到任何内容。我的问题是发送带有“条件”的消息时我没有收到任何东西,即使我在使用“to”时正常接收
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-02-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多