How to send FCM Push Notifications to multiple topics

前端 未结 1 840
臣服心动
臣服心动 2020-12-31 08:42

I am using php server to send FCM push notifications. I want to know how I can send push notifications to multiple topics at the same time.

Here is my code.

相关标签:
1条回答
  • 2020-12-31 08:59

    You use the condition key to send to multiple topics.

    For example:

    {
      "condition": "'dogs' in topics || 'cats' in topics",
      "priority" : "high",
      "notification" : {
        "body" : "This is a Firebase Cloud Messaging Topic Message!",
        "title" : "FCM Message",
      }
    }
    

    This would send the message to devices subscribed to topics "dogs" or "cats".

    Relevant quote from FCM docs:

    To send to combinations of multiple topics, the app server sets the condition key to a boolean condition that specifies the target topics.

    Note that you are limited to 2 boolean conditions, which means you can send a single message to at most 3 topics.

    Update: Now you can include 5 topics.

    You can include up to five topics in your conditional expression, and parentheses are supported. Supported operators: &&, ||, !. Note the usage for !:

    Read the documentation at: https://firebase.google.com/docs/cloud-messaging/send-message

    0 讨论(0)
提交回复
热议问题