解析目标推送通知特定用户 [英] Parse Target Push Notification Specific User
问题描述
因此,假设我的应用程序有两个用户,该用户具有消息传递组件.使用解析,是否可以将一个用户的推送通知发送给另一个用户?
So let's say I have two users of my app which has a messaging component. Using parse, is there a way I can send a push notification from one user to the other?
假定我有一种方法来唯一标识用户,例如电子邮件地址
assume I have a way to uniquely identify users, for example email address
推荐答案
是可能的.
-
首先在解析管理控制台中启用客户端推送
First enable client push in your parse admin console
使用ParsePush类,我们可以选择设置ParseInstallation查询,其中通知将针对特定的用户集,
Using ParsePush class, we have an option to set the ParseInstallation Query, where the notifications would be targeted to specific set of users,
https://parse.com/docs/push_guide#options-data/iOS
但是您可能无法发送给特定用户,因为ParseInstallation表没有这样的列以使其不受查询约束.
But you may NOT be able to send to a specific user, since the ParseInstallation table doesnt have such column to have it in query constraint.
因此,我在ParseInstallation表中添加了新字段'用户名',并在用户登录时更新了用户名.
So I added a new field 'username' in ParseInstallation table, and update the username whenever the user log in.
然后在发送推送时,根据此用户名创建ParseInstallation查询,以下示例适用于android,与其他操作系统类似
Then while sending the push, create the ParseInstallation query based on this username, the below example is for android, and it would be similar for other OS
JSONObject data = new JSONObject();
try {
data.put("action", "com.bt.yana.GOT_MESSAGE");
data.put("from", ParseUser.getCurrentUser().getUsername());
}catch (Exception e){
e.printStackTrace();
return;
}
ParsePush parsePush = new ParsePush();
parsePush.setData(data);
ParseQuery<ParseInstallation> parseQuery = ParseQuery.getQuery(ParseInstallation.class);
if(toUser!=null) {
parseQuery.whereEqualTo("username", toUser);
parsePush.setQuery(parseQuery);
parsePush.sendInBackground();
}
这篇关于解析目标推送通知特定用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!