Parse Cloud:向单个用户发送推送 [英] Parse Cloud: Send Push to a single user

查看:27
本文介绍了Parse Cloud:向单个用户发送推送的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Parse,但无法使此方法起作用.

I'm using Parse and I can't make this method to work.

这个想法是从云代码"中的任何平台向具有已知用户标识符的单个用户发送推送.

The idea is to send push to a single user with an already known user identifier from any platform within 'Cloud code'.

我试过的查询没有推送给那个用户(实际上没有推送给任何用户)

Queries I've tried without push being delivered to that user (actually no push was delivered to any user)

  • 通过用户指针进行PF安装:

  • PFInstallation through the user pointer:

var targetUser = new Parse.User();

targetUser.id = userID;

var query = new Parse.Query(Parse.Installation);

query.equalTo('user', targetUser);

在 PFUser 本身中查询

Query in PFUser itself

var query = new Parse.Query(Parse.User);

query.equalTo('objectId', userID);

该方法的完整代码:

Parse.Cloud.define("sendPushContactUser", function(request, response) {

// Get parameters
var userID       = request.params.userID; // I'm obviously passing this parameter in the method call


// Query
/* ------ query = Any of the above options ------ */


Parse.Push.send({
    where: query,
    data: {
        title   : "New message",
        alert   : "User message",   
        badge   : "Increment",
        sound   : "soundNotifUserContact.caf",
        "params" : {
            "pushType"  : 2,
            "userID"    : userID
        }
    }
}, {
    success: function() {
        response.success();
    },
    error: function(error) {
        response.error(error);
    }
    });

});

感谢您的时间和帮助.

推荐答案

这对我来说效果很好,但你必须在之前将你的用户与你的安装链接起来:

This works well for me, but you have to link your users with your installations before:

var query = new Parse.Query(Parse.User);
query.equalTo('username', 'Sento');
// Find devices associated with these users
var pushQuery = new Parse.Query(Parse.Installation);
// need to have users linked to installations
pushQuery.matchesQuery('user', query);


Parse.Push.send({
    where: pushQuery,
    data: {
        aps: {
            alert: "Test",
            sound: ""
        }
    }
}, {
    success: function () {
        response.success("Hello world!");
    },
    error: function (error) {
        response.error(error);
    }
});

这篇关于Parse Cloud:向单个用户发送推送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆