I am new to flutter and Firebase. I have registered my android app with firebase. My final goal is to send notifications to all the users automatically with a cloud function. So far, I know either I need to store the list of FCM tokens of all the users or subscribe them to perticular topic. I was thinking of going with subscribing to the topic, so that I will not have to store the tokens in my firestore. So, my question is where should I write
FirebaseMessaging.instance.subscribeToTopic("drawNotifications");
Because, If I put it in the main or initState, then it will be called everytime the user runs the app and if I do so, is it the right way to? Please feel free to let me know if I need to explain it more clearly as this is my very first question in Stackoverflow.
CodePudding user response:
It is good practice to give a user option to opt in to receive notifications. Prompt the user to get consent to receive notification and give an option to cancel at any point.
Although subscribeToTopic
can be called multiple times from the same device within certain restrictions.
The frequency of new subscriptions is rate-limited per project. If you send too many subscription requests in a short period of time, FCM servers will respond with a 429 RESOURCE_EXHAUSTED ("quota exceeded") response. Retry with exponential backoff.
https://firebase.google.com/docs/cloud-messaging/flutter/topic-messaging