What is the best way to generate Push notification using Firebase?

Asked

Viewed 375 times

5

I have the following problem:

I have a system where it is possible to register a series of tasks to be accomplished by a team or person. What I need is that whenever an order is finalized by a user, all others receive a notification (Push) saying it has been completed.

My doubts are:

a) Assuming that users can enter or leave the solver groups, this would be more recommended. Push to: Topics, Groups or single?

b) How to prevent Push from being generated after the user logs off into the app?

The solver groups would have a model similar to What’s app groups. If the user leaves the group, he is no longer notified.

1 answer

0

a) Short answer: Topics.

Long answer:

Single Devices would require you to create your own logic for the user to log in and out of groups. You would have to store each user’s token in a database (which can be more expensive depending on the limits of your database).

Groups - although the name is suggestive, the documentation indicates that groups are for you to push to all devices that belong to a user. For example, if one of your users uses the app on iPhone, an Android tablet, and a computer (via the Web), you would put those 3 devices in a group to receive the same notifications at all times.

Topics - Just like in groups, you don’t need to manage the tokens of each device that is part of a "group" (other than the single Devices) because Firebase does it for you. And the SDK is very easy to use. For a user to join a group, you would:

FirebaseMessaging.getInstance().subscribeToTopic("idGroup");

And for him to leave the group:

FirebaseMessaging.getInstance().unsubscribeFromTopic("idGroup");

b) If you are using Firebase Auth, when logging off it will no longer have access to push Notifications. If you’re not using Auth, try calling deleteInstanceId() during the log off.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.