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

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

问题描述

我正在使用Parse,我无法使此方法正常工作。



这个想法是向具有已知用户标识符的单个用户发送推送



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




  • PF通过用户指针安装:



    var targetUser = new Parse.User();



    targetUser.id = userID;



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



    query.equalTo('user',targetUser);


  • 本身



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



    query.equalTo('objectId',userID);




方法的完整代码:

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

//获取参数
var userID = request.params.userID; //我明显在方法调用

$ b中传递此参数
//查询
/ * ------ query =任何上述选项--- --- * /


Parse.Push.send({
其中:query,
数据:{
标题:新消息
alert:User message,
badge:Increment,
sound:soundNotifUserContact.caf,
params:{
pushType: 2,
userID:userID
}
}
},{
success:function(){
response.success();
},
error:function(error){
response.error(error);
}
});

});感谢您的时间和帮助。

>解决方案

这对我来说很好,但是你必须在你的安装之前链接你的用户:

  var query = new Parse.Query(Parse.User); 
query.equalTo('username','Sento');
//查找与这些用户相关的设备
var pushQuery = new Parse.Query(Parse.Installation);
//需要用户链接到安装
pushQuery.matchesQuery('user',query);


Parse.Push.send({
其中:pushQuery,
数据:{
aps:{
alert:Test ,
sound:
}
}
},{
success:function(){
response.success(Hello world! ;
},
error:function(error){
response.error(error);
}
});


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)

  • PFInstallation through the user pointer:

    var targetUser = new Parse.User();

    targetUser.id = userID;

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

    query.equalTo('user', targetUser);

  • Query in PFUser itself

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

    query.equalTo('objectId', userID);

Full code for the method:

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);
    }
    });

});

Thanks for your time and help.

解决方案

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);
    }
});

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

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