FCM 目标条件语法
FCM Target condition syntax
我一直找不到任何官方 FCM 文档来解释构造传递给 FCM 的条件字符串以发送有针对性的推送的正确语法。我正在使用出色的 Firebase Admin SDK for PHP,我可以用它来定位外发消息收件人
CloudMessage::withTarget('condition',$condition)->withNotification($notif)->withData($data);
通常,我可以建立简单的条件,例如
"('topicFoo' in topics) && !('topicBar' in topics)";
这将确保消息发送给 topicFoo
的所有订阅者,他们不是主题 topicBar
的订阅者。我通过反复试验为自己解决了这个问题。但是假设我想构建更复杂的条件,例如
"(('topicFoo1' in topics) || ('topicFoo2' in topics)) && !(('topicBar1 in topics) || ('topicBar2' in topics))"
虽然我也可以通过反复试验来解决这个问题,但最好有明确的 Google 文档来解释可以做什么和不能做什么。 FCM 是否存在最大条件复杂度?
据我所知,关于 sending messages to topics 的文档包含有关条件的这一部分:
To send a message to a combination of topics, specify a condition, which is a boolean expression that specifies the target topics. For example, the following condition will send messages to devices that are subscribed to TopicA
and either TopicB
or TopicC
:
"'TopicA' in topics && ('TopicB' in topics || 'TopicC' in topics)"
FCM first evaluates any conditions in parentheses, and then evaluates the expression from left to right. In the above expression, a user subscribed to any single topic does not receive the message. Likewise, a user who does not subscribe to TopicA
does not receive the message. These combinations do receive it:
TopicA
and TopicB
TopicA
and TopicC
You can include up to five topics in your conditional expression.
还有一个用于发送到带有条件的主题的代码片段,因此我建议您也在 link 中查看它。
我一直找不到任何官方 FCM 文档来解释构造传递给 FCM 的条件字符串以发送有针对性的推送的正确语法。我正在使用出色的 Firebase Admin SDK for PHP,我可以用它来定位外发消息收件人
CloudMessage::withTarget('condition',$condition)->withNotification($notif)->withData($data);
通常,我可以建立简单的条件,例如
"('topicFoo' in topics) && !('topicBar' in topics)";
这将确保消息发送给 topicFoo
的所有订阅者,他们不是主题 topicBar
的订阅者。我通过反复试验为自己解决了这个问题。但是假设我想构建更复杂的条件,例如
"(('topicFoo1' in topics) || ('topicFoo2' in topics)) && !(('topicBar1 in topics) || ('topicBar2' in topics))"
虽然我也可以通过反复试验来解决这个问题,但最好有明确的 Google 文档来解释可以做什么和不能做什么。 FCM 是否存在最大条件复杂度?
据我所知,关于 sending messages to topics 的文档包含有关条件的这一部分:
To send a message to a combination of topics, specify a condition, which is a boolean expression that specifies the target topics. For example, the following condition will send messages to devices that are subscribed to
TopicA
and eitherTopicB
orTopicC
:"'TopicA' in topics && ('TopicB' in topics || 'TopicC' in topics)"
FCM first evaluates any conditions in parentheses, and then evaluates the expression from left to right. In the above expression, a user subscribed to any single topic does not receive the message. Likewise, a user who does not subscribe to
TopicA
does not receive the message. These combinations do receive it:
TopicA
andTopicB
TopicA
andTopicC
You can include up to five topics in your conditional expression.
还有一个用于发送到带有条件的主题的代码片段,因此我建议您也在 link 中查看它。