简体   繁体   中英

FCM Notification to specific wordpress user

i am developping an android application based on a wordpress blog where users can post their own articles, i work with WP REST API to get posts , comments and users ...

I would like to send a notification automatically to the user when his article got a new comment , i have installed FCM correctly and tested the simple forme of notifications but i need to :

  • Trigger FCM Notification on new comment sent ( Or just on a button click )
  • Specify receiver so the notification is sent to logged in user with the right email/username

I thought of

  • working with setting User Property for every user logged like this :

mFirebaseAnalytics.setUserProperty("user_name_for_notification", "the_username");

  • Sending notification for all devices then handle it in onMessageReceived

but i don't think those are good ideas

So , any ideas where to start

thank you

FCM can send notifications with three different targeting methods:

  1. to a specific FCM token/instance ID token, which identifies an installation of a specific application on a specific device.
  2. to a group of such device/instance IDs.
  3. to a specific topic, which FCM clients can subscribe to.

Firebase Cloud Messaging does not have the concept of a user, therefor it cannot target users directly. If you want to target users, you will have to map them to one of the targeting methods outline above.

The most common ways that I know of:

  1. Store the token(s) for a user in a database under their UID, and then send to the user's token(s) when you need to target the user.
  2. Give each user their own topic, based on their UID. Have the app subscribe to that topic, and send message to the user's topic when you need to target them.

Also see:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM