简体   繁体   中英

Difference between topic messaging and device token cloud function push notification?

In Firebase cloud function can send push notification to any user if the user device token is stored in Firebase database. Again if the user subscribes to a topic then also another user can send a notification to the user. Now the question is that in what situation we should use topic messaging and in what situation we should use cloud function to send the notification. If any user subscribes to his unique ID (as provided by Firebase) then anyone can send topic messaging to him by publishing topic messaging to that unique ID. Is it a good approach or we should use cloud function to send push notification to that user using the device token. Is it a good idea to subscribe to his own unique ID to get a notification. Please help me to resolve my issue. Is topic messaging is free to use?

Firebase Cloud Messaging is completely free to use, including the use of topics.

When you use topics , you separate the sending of messages about a topic, from the fact that an install of your app subscribes to that topic. This means you can add subscribers to the topic later, without having to write additional code or even data (as the list of tokens that are subscribed to a topic is handled by FCM itself).

On the other hand: topics are public . Once somebody knows the topic ID, they can subscribe to that topic, and receive any messages you send to that topic.

The alternative to using topics is sending messages directly to FCM Instance ID tokens . In that case you'll keep a list of tokens somewhere yourself, and determine what token(s) to deliver the message to. In this case, you fully control who receives the message, but will have to maintain your own list of tokens, and the mapping of what token receives what message(s).

Note that sending messages (no matter whether to topics or to tokens) can be done from any trusted environment, like your development machine, a server you control, or Cloud Functions. And sending messages (no matter whether to topics or to tokens) can't be (securely) done from the client-side code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM