Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to unsubscribe from FCM notifications after logout from app?

I have implemented Firebase cloud messaging in my app for push notifications. Everything working fine. But notifications are getting even user logged out from app.

I heard that, I need to delete the FCM token when user logged out from app.

So I did like this in logout method:

-(void)logout{
        [[FIRInstanceID instanceID] deleteIDWithHandler:^(NSError *error){
            NSLog(@"%@",error);
        }];
}

But this is not working and next time when user logged in [[FIRInstanceID instanceID]token] is coming as null.

How to do this?

like image 603
Himanth Avatar asked Dec 07 '16 09:12

Himanth


People also ask

How do I unsubscribe from FCM?

When a client app subscribes to a new topic name (one that does not already exist for your Firebase project), a new topic of that name is created in FCM and any client can subsequently subscribe to it. To unsubscribe, the client app calls Firebase Cloud Messaging unsubscribeFromTopic() with the topic name.

Can FCM notification on Android overwrite previous one?

If specified and a notification with the same tag is already being shown, the new notification replaces the existing one in the notification drawer.

What does FCM name mean when I turn on my phone?

Firebase Cloud Messaging (FCM) is a cross-platform messaging solution that lets you reliably send messages at no cost. Firebase. 339K subscribers. Introducing Firebase Cloud Messaging.


1 Answers

You can delete the token, but it's better to simply cancel the subscription. How to do that, depends on how you subscribed to the updates in the first place.

If you subscribed to a topic, you'll want unsubscribe when the user signs out.

like image 164
Frank van Puffelen Avatar answered Sep 27 '22 21:09

Frank van Puffelen