Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the best way to store FCM tokens?

I am trying to send push notifications programmatically to and iOS app using the Cloud Functions. In order to do this, I need to get the target user FCM token.

My idea of doing this is storing a dictionary of user emails and their FCM tokens on the real-time database. This way, whenever the Cloud Functions need to send a push notification to the user, it can look up the current token.

However, while looking at the docs, I noticed Firebase said this:

An ID generated by the FCM SDK for each client app instance. Required for single device and device group messaging. Note that registration tokens must be kept secret.

If FCM tokens need to be kept secret, then how should I send a push notification programmatically from Cloud Functions? Or is storing on the database "secret" enough?

like image 701
ndduong Avatar asked Jul 15 '17 05:07

ndduong


People also ask

Is FCM token and device token same?

They are often used interchangeably and neither are really "official" terms. For the most part, both terms refer to your APNS/FCM token, however device token has historically been used for other things like unique device identifiers.

How long FCM Token expired?

It doesn't expire though. It renews itself if one of the following happens. According to https://firebase.google.com/docs/cloud-messaging/android/client: -The app deletes Instance ID.

Is there any limit for FCM?

Maximum message rate to a single device For Android, you can send up to 240 messages/minute and 5,000 messages/hour to a single device.


1 Answers

Storing the token on the Firebase DB should be secured enough (I think the docs needs re-wording on this). Make sure that the node you plan to save the registration tokens is properly secured with the Firebase Rules - allowing only the corresponding users to read them. However since you're using Cloud Functions to read them, you should be fine.

like image 137
AL. Avatar answered Nov 06 '22 10:11

AL.