简体   繁体   English

FCM 通知特定 wordpress 用户

[英]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 ...我正在开发一个基于 wordpress 博客的 android 应用程序,用户可以在其中发布自己的文章,我使用 WP REST API 来获取帖子、评论和用户...

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 :当他的文章有新评论时,我想自动向用户发送通知,我已经正确安装了 FCM 并测试了简单的通知形式,但我需要:

  • Trigger FCM Notification on new comment sent ( Or just on a button click )发送新评论时触发 FCM 通知(或只需单击按钮)
  • 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"); mFirebaseAnalytics.setUserProperty("user_name_for_notification", "the_username");

  • Sending notification for all devices then handle it in onMessageReceived为所有设备发送通知,然后在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: FCM 可以使用三种不同的定位方法发送通知:

  1. to a specific FCM token/instance ID token, which identifies an installation of a specific application on a specific device.到特定的 FCM 令牌/实例 ID 令牌,它标识特定设备上特定应用程序的安装。
  2. to a group of such device/instance IDs.到一组此类设备/实例 ID。
  3. to a specific topic, which FCM clients can subscribe to.到特定主题,FCM 客户端可以订阅。

Firebase Cloud Messaging does not have the concept of a user, therefor it cannot target users directly. Firebase Cloud Messaging 没有用户的概念,因此无法直接定位用户。 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.将用户的令牌存储在其 UID 下的数据库中,然后在需要定位用户时发送到用户的令牌。
  2. Give each user their own topic, based on their UID.根据用户的 UID,为每个用户提供他们自己的主题。 Have the app subscribe to that topic, and send message to the user's topic when you need to target them.让应用订阅该主题,并在需要定位用户时向用户的主题发送消息。

Also see:另见:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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