更新时间:2023-02-26 21:10:02
是可能的.
首先在解析管理控制台中启用客户端推送
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();
}