6

I'm new using the Firebase Cloud Message. I built an IOS app to receive push notifications. The app works fine. I send messages from the Firebase console and they're displayed correctly.

Now I`m trying to build an web api to allow my customer to send the push messages (without accessing the firebase console). Studying the documentation here I realized that I've always to have a "to", meaning a group, topic or device id.

My question is: can I send a message to all devices (like I can do in the console)? I yes, how so?

Thanks in advance!

AL.
  • 36,815
  • 10
  • 142
  • 281

2 Answers2

5

You can make use of topics. Given that all of your users are subscribed to a specific one. Just like what I mentioned here (removed some parts, just check them out if you want):

If you are looking for a payload parameter to specify that you intend the message for all your users, unfortunately, it doesn't exist.

Commonly, when sending notifications to multiple users, you can make use of the registration_ids parameter instead of to. However, it only has a maximum of 1000 registration tokens allowed. If you intend to use this, you can make batch requests of 1000 registration tokens each, iterating over all the registration tokens you've stored in your app server.

However, do keep in mind that Diagnostics for messages sent to Topics are not supported.

Community
  • 1
  • 1
AL.
  • 36,815
  • 10
  • 142
  • 281
  • Thanks for your response. I was already suspecting this, but I really needed a confirmation. I just made a test using Topics and it worked like a charm. I'll change my app to subscribe to a topic. – Danilo Barreto Sep 29 '16 at 14:19
  • @DaniloBarreto You're welcome. If your main goal is to simply send the message to a lot of users. Topics is the way to go. Cheers! – AL. Sep 29 '16 at 14:22
  • 1
    @AL. perfect answer – Adham Feb 06 '17 at 09:43
  • @Adham Thanks. Cheers! :) – AL. Feb 06 '17 at 10:20
1

I found this:

!('TopicA' in topics)

With this expression, any app instances that are not subscribed to TopicA, including app instances that are not subscribed to any topic, receive the message.

So you could probably use

condition="!('nonExistingTopic' in topics)"
point
  • 83
  • 4