enou plus
enou plus

Reputation: 43

Firebase Cloud Messaging Unsubscribe from all topics

I have a simple news app for my college. To send notifications, I use firebase cloud messaging

My problem: I want to send notifications based on the version of my app from the API. when my app version is 2. I will send a notification to the topic v2. but when users update the app to v3 and I need to maintain v2 of my app then how can I target v3 only

Upvotes: 0

Views: 2357

Answers (1)

Frank van Puffelen
Frank van Puffelen

Reputation: 598623

You can use a condition to send to folks who have only subscribed to v2 and not v3.

condition: "'v2' in topics && !'v3' in topics"

Note that this allows up to 5 clauses only, so I'd recommend also updating the logic in your app to remove subscriptions to older versions. You don't even need to do this conditionally, so it can be as simple as:

Firebase.messaging.subscribeToTopic("v3");
Firebase.messaging.unsubscribeFromTopic("v2");
Firebase.messaging.unsubscribeFromTopic("v1");

If the user is not/no longer subscribed to a topic, calling unsubscribeFromTopic doesn't do anything (but doesn't fail).

Upvotes: 2

Related Questions