Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Firebase FCM&x27;条件';字段不起作用_Firebase_Firebase Cloud Messaging - Fatal编程技术网

Firebase FCM&x27;条件';字段不起作用

Firebase FCM&x27;条件';字段不起作用,firebase,firebase-cloud-messaging,Firebase,Firebase Cloud Messaging,我无法使用“条件”字段发送要发送到多个主题的FCM消息。出于某种原因,即使FCM没有发送任何错误,我的设备在使用此字段时也不会收到消息 当我发送此邮件时: { "to": "/topics/topic1", "data": { "message": "test" } } 消息已收到,但我没有收到任何与此相关的信息: { "condition": "'topic1' in topics", "data": { "message": "test" } } 即使两条

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

当我发送此邮件时:

{
"to": "/topics/topic1",
"data": {
    "message": "test"
    }
}
消息已收到,但我没有收到任何与此相关的信息:

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

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

您必须为您的主题订阅您的设备,您也可以使用rest服务进行订阅。 当你想发送信息时,你可以提供标题和正文

例如:

{
  "message":{
        "condition": "'topic1' in topics",
         "data": {
           "message": "test"
       },
   "notification" : {
         "body" : "This is an FCM notification message!",
         "title" : "FCM Message",
      }
   }
}
具有模拟响应 主题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”时正常收到消息。您找到解决方案了吗?如果有的话,请分享。很遗憾,我没有。我不得不用其他方法来做。祝你好运。