2
votes

I am trying out firebase cloud messaging (React-native-firebase) and it seems that I am only able to push notifications to all android/ios users, not specific users. Is there a way to target a specific user. Like if a user invites another user only send notification to that one specific user?

2
FCM does not have its own concept of a "user". It just knows devices. You will have to associate device tokens to each user account, then send messages to just the devices associated with that user. - Doug Stevenson

2 Answers

4
votes

The flow can be this one:

  • User allow notifications on their device(s)
  • Grab the generated token and store it in the user document inside a tokens array.
  • (If the same user connects to your app in another device, add the new token in the tokens array)
  • If you want to target a specific user, get his UID and send a notification to their devices.
  • You can also subscribe a user to a topic and send a notification to users subscribed to that topic.
2
votes

two way:

init

  • your client-side subscribe the topic.
subscribeToTopic("weather")
  • your client-side report the user property
setUserProperty("name","TOM");

Firebase Cloud Message Console

crate a notification item like this way enter image description here