4

There are several ways to send FCM messages and I don't understand which one to use even if I read the documents over and over.

My use case: I have a user that is logged into the app on her iPhone, iPad and Android tablet. I want to make sure the push notifications are sent to all of her devices.

There are three ways to do this (I'm using the admin to send the push notifications):

  • Topic messaging (messaging().sendToTopic): My understanding this is for sending the same notification to larger groups. For example a topic could be all users that want weather notifications for New York. Not for my use case.

  • Send Multicast (messaging().sendMulticast([array of tokens]): My understanding this will send the same message to all device tokens in the array (up to 100). This seems perfect for my use case, right?

  • Device group messaging (messaging().sendToDeviceGroup): I don't really understand this one. Why use this instead of multicast or topics?

For my use case it seems the best way is to each time a FCM token is updated I add this token to the user in the database. I then send the notification using the admin.messaging().sendMulticast([array of tokens]). Is this what you would recommend? Why or why not?

Martin
  • 7,190
  • 9
  • 40
  • 48

1 Answers1

4

You probably want to use multicast if you're targeting an individual user's specific devices. You probably don't want to use device groups. I suggest reading the documentation to understand how device groups work:

Device group messaging allows you to add multiple devices to a single group. This is similar to topic messaging, but includes authentication to ensure that group membership is managed only by your servers. For example, if you want to send different messages to different phone models, your servers can add/remove registrations to the appropriate groups and send the appropriate message to each group. Device group messaging differs from topic messaging in that it involves managing device groups from your servers instead of directly within your application.

Device groups are basically just topics whose membership is fully managed by your server code, not by client code.

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
  • Thanks for making it clear! My issue was that in the documentation under "Send messages to multiple devices" (https://firebase.google.com/docs/cloud-messaging/ios/send-multiple) the only suggestions are "Topic messaging" and "Device group messaging". Also when reading other questions on Stackoverflow I see over and over again that people are using "Device group messaging" for my use case which made me wondering. – Martin May 27 '20 at 16:02