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?
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.
If specified and a notification with the same tag is already being shown, the new notification replaces the existing one in the notification drawer.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With