Oscar Junius
Oscar Junius

Reputation: 560

Device to device push notifications logic Swift IOS Firebase

My goal is to implement a function where, when a user (lets call him User1) sends a message to another user (User2), a notification is sent to User2´s device, so he can see the message right on the lock screen. I have already implemented a function where this works. My only problem now is that when I send the push Notification from User1´s device to User2´s device, I don't know if User2 is on the account that he should receive the message on. If User2 has logged into a different account and User1 sends him a message, he sees this message, although User2 is in a different account and shouldn't see this message. Is there any way to know if a user logged into a different account and to then block the notification from showing on User2´s device?

Upvotes: 1

Views: 687

Answers (1)

Frank van Puffelen
Frank van Puffelen

Reputation: 600016

Firebase Cloud Messaging has no concept of a user. It only knows about devices, or more explicitly app instances (a specific app on a specific device is an app instance).

If your use-case is based around users, your application logic is making a mapping from a user to their FCM instance ID/IDs. If you want the user to not receive a message anymore on a specific app instance, you need to remove the mapping you made.

The most common way to do this is to remove the mapping when the user signs out from your application on a specific device.

Since this is all rather abstract, I recommend also checking out:

Upvotes: 1

Related Questions