简体   繁体   English

向特定用户发送解析推送通知

[英]Send Parse push notifications to specific users

getting straight to the point, I can send push notifications from my app to other apps which have the same Channel name as it. 直截了当,我可以将推送通知从我的应用发送到与该应用具有相同频道名称的其他应用。 Now my requirement is that I need to send to a particular user. 现在,我的要求是我需要发送给特定用户。 Read some documentation about it but was still unclear of how to achieve that. 阅读有关它的一些文档,但仍不清楚如何实现。 This is what I've done so far. 到目前为止,这是我所做的。

Parse.initialize(this, "xxxxxxxxxxxxxxxxxxxxxxx", "yyyyyyyyyyyyyyyyyyyyy");
ParseInstallation.getCurrentInstallation().saveInBackground();
ParsePush.subscribeInBackground("words");

On Button Click: 在按钮上单击:

 ParseQuery pushQuery = ParseInstallation.getQuery();
    pushQuery.whereEqualTo("user", receiver);

    ParsePush push = new ParsePush();
    push.setQuery(pushQuery);

    push.setChannel("words");
    push.setMessage(ParseUser.getCurrentUser().getUsername() + " sent you a Gift");
    push.sendInBackground();

删除push.setQuery(pushQuery);

My solution is good for you only if: 仅在以下情况下,我的解决方案才对您有好处:

you associating every installation with user: ParseInstallation.currentInstallation.put("user",ParseUser.currentUser) 您将每个安装与用户相关联: ParseInstallation.currentInstallation.put("user",ParseUser.currentUser)

        //search all receiver users
        ParseQuery<ParseUser> userQuery = ParseUser.getQuery();
        userQuery.whereEqualTo("user", receiver);
        userQuery.findInBackground(new FindCallback<ParseUser>() {
            public void done(List<ParseUser> users, ParseException e) {
                if (users != null && users.size() > 0) {
                    //now you have all receivers
                    for (int i = 0; i < users.size(); i++) {
                        ParseUser user = users.get(i);
                        //now searching needed channel inside array of receivers
                        ArrayList<JSONObject> channels = (ArrayList<JSONObject>) user.get("channels");
                        if (channels.contains("words")){
                            //here sending the push
                            ParseQuery<ParseUser> userQuery = ParseUser.getQuery();
                            ParseQuery<ParseInstallation> installationQuery = ParseInstallation.getQuery();
                            userQuery.whereEqualTo("user", user);
                            installationQuery.whereMatchesQuery("user", userQuery);

                            ParsePush push = new ParsePush();
                            push.setQuery(installationQuery);
                            push.setMessage(ParseUser.getCurrentUser().getUsername() + " sent you a Gift");
                            push.sendInBackground();
                        }
                    }
                }
            }
        });

If your user using the same account in many devices with different channels so this is not solution for you. 如果您的用户在具有不同渠道的许多设备中使用相同的帐户,那么这不是您的解决方案。

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

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