向特定wordpress用户的FCM通知 [英] FCM Notification to specific wordpress user
问题描述
我正在开发一个基于wordpress博客的android应用程序,用户可以在其中发布自己的文章,我使用WP REST API来获取帖子,评论和用户...
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 ...
当他的文章有新评论时,我想自动向用户发送通知,我已经正确安装了FCM并测试了通知的简单形式,但是我需要:
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通知(或单击按钮即可)
- 指定接收者,以便使用正确的电子邮件/用户名将通知发送给登录用户
我想到了
- 为每个这样登录的用户设置用户属性:
mFirebaseAnalytics.setUserProperty("user_name_for_notification","the_username");
- 发送所有设备的通知,然后在 onMessageReceived 中进行处理
- 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
谢谢
推荐答案
FCM可以使用三种不同的定位方法发送通知:
FCM can send notifications with three different targeting methods:
- 特定的FCM令牌/实例ID令牌,该令牌标识特定应用程序在特定设备上的安装.
- 到一组此类设备/实例ID.
- FCM客户可以订阅的特定主题.
Firebase Cloud Messaging没有用户的概念,因此它无法直接定位用户.如果要定位用户,则必须将他们映射到上述概述的定位方法之一.
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:
- 在用户的UID下将用户的令牌存储在数据库中,然后在需要定位用户时发送给用户的令牌.
- 根据每个用户的UID为他们提供自己的主题.让应用程序订阅该主题,并在需要定位用户时将消息发送到用户的主题.
另请参阅:
- 如何使用Firebase Messaging发送一对一消息
- 使用Firebase发送消息给自定义用户
- 按用户向用户发送Firebase Cloud Messaging通知财产
- 如何向用户发送数据消息来自Rest API的细分
这篇关于向特定wordpress用户的FCM通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!