Flutter: Cloud Message Not Delivered to Topic Subscriber - firebase

I call _firebaseMessaging.subscibeToTopic('topic-title'); to subscribe user to a topic on button click.
Some minutes after, the new topic showed at firebase cloud message console and i sent a message to the topic but I didn't received it. I don't understand why this is not working. I think there should be a option to add user's token to the subscribeToTopic('topic-title', token) or is the token automatically detected? Because am afraid the topic was only created with no token added.
Please i need help.

You don't need user token for topic notification
firebaseMessaging.subscribeToTopic('newJobs'); //you are doing it correctly.
Now I think all you need is to minimize your running app while sending the notification because notification will not appear, if your app is on the resume state.

Related

get all notifications sent to a user

I'm using FCM FirebaseMessaging to send push notifications to user of my app.
Is there a way to get all notifications sent to one single user or I have to store them in Firestore db?
It's not entirely clear to me what you mean by "get all notifications sent to one single user". But if you're trying to get a history of all messages previously sent to a user via the FCM API, that's not possible. FCM doesn't remember anything about messages previously sent. You have to keep that record yourself, if that's what you need.

email delivery report in Firebase

I want to know whether the email is delivered to the respective email account or not Using Firebase Auth API's
Let me know if there is any workaround ?
I assume you are referring to the Firebase Authentication. The user is retrieved from mAuth.getCurrentUser() method, and the sendEmailVerification() method is called on it. This gets Firebase to send the mail, if the task was successful, you'll see that a toast will pop up showing that it happened.
sendEmailVerification()

Firebase Notification by topic

I am new to firebase. I want to send notification to my list of followers(group of members like instagram).
I created a unique topic for each user and all the followers of a user will subscribe to the topic. when i send a notification to the topic, notification not delivered to all followers consistently.
When User clicks follow button i am subscribing to the topic by
FirebaseMessaging.getInstance().subscribeToTopic(FollowerUserID);
by clicking unfollow i am unsubscribing the topic
FirebaseMessaging.getInstance().unsubscribeFromTopic(FollowerUserID);
I have used Firebase cloud functions for pushing notification to the Topic.
If Firebase Token changed for a user whether we need subscribe the topic again?
I don't know how the subscribe/unsubscribe model works. will anyone explain how its works ?
kindly help me get out of this problem.
Suggest me the best way to send notifications to group of peoples(Followers).
First thing first.
If a firebase user token changes and that token was subscribed to a cloud messaging notification then he will no longer receive any notifications, also if he was subscribed to a topic and that topic changes he won't get any notifications from the new topic
For your business logic, I'd make a cloud messaging topic for each user and whenever someone follows that user I will subscribe that user token to the topic of the followed user.
say user X followed user Y, and user Z followed user X. both Y and Z will subscribe to topic X.
check this link
https://firebase.google.com/docs/cloud-messaging/admin/manage-topic-subscriptions
Firebase Cloud Messaging topics subscribe based on Instance ID, not FCM Token. An Instance ID uniquely identifies an app device instance and does not change unless the user uninstalls the app. If an app instance is subscribed to a topic, it will remain subscribed to it. While FCM Tokens periodically refresh, this does not affect topic subscriptions. There is no need to resubscribe users every time a token refreshes. See the guide for some useful information. You can also see the reference indicating how subscribeToTopic works with the Instance ID.

firebase - when user dismiss a notification

Im using inoic with cordova-plugin-fcm
There's any way to handle when user dismiss a notification, because I need to do store some data when a notification arrives.
tks for any help.
There are two types of messages that you can send with FCM:
notification messages, which are primarily meant to be displayed to the user.
data messages, which are handled by your application code.
If you send a notification messages, then your code can handle the message while the app is active. But if your app is not active, the message is handled by the system and displayed to the user. Your code is not invoked in this case.
If you send a data message, it is always handled by your code. For your use-case, these sound like the better match.

Push Notifications through Firebase

Yesterday Google has announced a new set of tools for Firebase, one of them was Notifications the ability to send notifications from server to devices which are using my app.
But can we now notify users when they receive a new message?
And if not, is there a way around to achieve this?
Looking at the documentation, this doesn't seem currently possible automatically. Here is a possible way to accomplish it "manually" with another server:
Subscribe a user to it's own user ID
In android
FirebaseMessaging.getInstance().subscribeToTopic("InsertUserIDHere");
In IOS
[[FIRMessaging messaging] subscribeToTopic:#"/topics/InsertUserIDHere"];
Setup an outside server that checks every sent messages. When a message is sent, the server should create a notification that includes the recipient's user ID as the topic.
Look here for more info.
You can send messages to group of users (targeting a specific "topic") or to a single device (targeting a Firebase Cloud Messaging token).
To subscribe a device to a topic use:
FirebaseMessaging.getInstance().subscribeToTopic("topicName");
To obtain the device token use (*1) :
FirebaseInstanceId.getInstance().getToken();
Then you can use the Firebase Notificaitons web console, or the FCM server API if you want to send messages from your server.
See: https://firebase.google.com/docs/cloud-messaging/downstream#sending_topic_messages_from_the_server
Notes:
[1] getToken() can return null if the token is not yet available.
You can use the callback onTokenRefresh() to be notified when the token is available and when the token is rotated.
See: https://firebase.google.com/docs/cloud-messaging/android/client#sample-register

Resources