Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send FCM Notification to a list of specific device tokens using the v1 API

I want to use the new FCM HTTP v1 API, which is documented here FCM HTTP v1 API Documentation, to send a notification to multiple devices at once, but without using topics, or groups (let's say I want to send a notification to 10 random winners of some lottery). I know that in the previous version (Legacy FCM HTTP Protocol), this was possible by using the registration_ids parameter, but I don't see anything similar in the current API. Am I missing something? Is there a way to do this without using the legacy API?

like image 888
Haf_SK Avatar asked Jun 20 '18 15:06

Haf_SK


People also ask

How do I send FCM notification to one device?

For sending FCM notification payload you can use Firebase Cloud Messaging Tool in firebase console. And click on Send your first message. Then enter the Title and body field. If you wish to send it to a particular device then click on Send test message and enter the FCM registration token.


2 Answers

There is currently no other way to send to multiple tokens besides using topics for FCM v1.

In your mentioned use case, if I'm using v1, I would probably go at something like, after selecting the winning tokens, you subscribe them to a topic like winningTokens<date_here> then send the message.

like image 108
AL. Avatar answered Nov 15 '22 16:11

AL.


For other use cases, the best way to send to multiple devices via v1 API depends on your application. For example, the accepted answer would not be a good solution for a private chat application where another user can guess the topic name and evesdrop on the conversation by subscribing to the topic. In that scenario iterating over the device list and making multiple send calls to a single device would be better.

like image 23
Jannie Theunissen Avatar answered Nov 15 '22 16:11

Jannie Theunissen