LoginSignup
0
0

More than 3 years have passed since last update.

FCMで条件に送信する際に ! を使う。

Posted at

したいこと

FCMを送る際に、TopicAに登録されているtoken以外に送信したい。

方法

const condition: string = `!('TopicA' in topics )` 
//CloudFunctionsで送信することを想定
admin.messaging().sendToCondition(condition, message)
            .then((res) => {
                console.log(res)
            })
            .catch((err) => {
                console.error(err)
            })

で終わり。

これを使うことでブロックしているユーザーには通知が行かないということが実現できる。

すぐ終わった内容をわざわざ書いた理由

Firebaseの公式ドキュメントでは &&、|| についてしか書かれていなかったから。

条件式には最大 5 つのトピックを含めることができ、かっこを使用できます。 サポートされる演算子: &&、||。

StackOverflowの質問によると2018年3月16日時点では書かれてあったらしい。
ということでもしかしたらいつか無効になるかもしれない。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0