How to send notifications to all devices using Firebase Cloud Messaging

firebase push-notification firebase-cloud-messaging

6980 просмотра

3 ответа

76 Репутация автора

On the Firebase doc, it always has a "to" field with a device/token id... but how can I get it to send the notification to all devices. What do I replace the to field with, or what value do I put in there. I'd removed it altogether but it comes back with an error asking for it. Any ideas?

{
   "to" : "bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...",
   "data" : {
     "Nick" : "Mario",
     "body" : "great match!",
     "Room" : "PortugalVSDenmark"
   },
 }
Автор: Mr Jones Источник Размещён: 18.07.2016 01:37

Ответы (3)


3 плюса

284387 Репутация автора

You cannot send to "all devices".

Instead you can target a specific device, a group of devices or a topic when using the Firebase Cloud Messaging API. Alternatively you can send to a user segment, a specific device, or a topic when using the Firebase Notifications console.

With Firebase Notifications you can get closest, since there is a default user segment that includes all devices that have a specific app installed. So if you have an Android and an iOS app, that would be two notifications. But there's no programmatic way to send to such an audience (yet).

Автор: Frank van Puffelen Размещён: 18.07.2016 02:34

0 плюса

363 Репутация автора

You can use the Firebase console to send notification to all the devices.

Автор: Anandroid Размещён: 19.07.2016 12:02

2 плюса

163 Репутация автора

As Frank van Puffelen said there isn't a way to send to all devices. What you could do is to subscribe everyone to a single topic in the app side using:

FirebaseMessaging.getInstance().subscribeToTopic("TopicName");

So your message would look like this:

  {
   "to"   : "/topics/TopicName",
   "data" : {
     "Nick" : "Mario",
     "body" : "great match!",
     "Room" : "PortugalVSDenmark"
   },
 }

The topic is automatically created in the Firebase server side, but sometimes it takes a while to show up in the Firebase drop down list.

The number of users in a single topic are unlimited.

Автор: emportella Размещён: 29.03.2017 06:07
Вопросы из категории :
32x32