问题描述
我想从解析云代码向特定用户发送推送通知.因此,我在解析表的安装类中创建了一个用户部分,并将用户对象 ID 保存在那里,以便我可以通过 ID 定位用户并从云代码发送推送.https://www.dropbox.com/s/dvedyza4bz3z00j/userObjec.PNG?dl=0
I want to send a push notification from parse cloud code to a specific user.So i have created a user section in installation class of my parse table and i save the user object id there so i can target the user by id and send push from cloud code.https://www.dropbox.com/s/dvedyza4bz3z00j/userObjec.PNG?dl=0
从 parse.com 做起来很简单,我是这样做的,有条件https://www.dropbox.com/s/1mb3pb2izb0jlj9/pushs.PNG?dl=0
From parse.com it is very simple to do, i did it like this with conditionhttps://www.dropbox.com/s/1mb3pb2izb0jlj9/pushs.PNG?dl=0
但是我想要做的是当用户在我的类是Ticket"的类中添加新对象时发送推送通知.
But what i want to do is to send a push notification when a user adds new object in the class my class is "Ticket".
此类已启用 ACL.我想要做的是非常简单地向通过云代码创建对象的用户发送推送
This class has ACL enabled.What i want to do is very simple send push to the user which created the object through cloud code
这是我的云代码
Parse.Cloud.afterSave("Ticket", function(request) {
var pushQuery = new Parse.Query(Parse.Installation);
Parse.Push.send({
where: pushQuery,
data: {
alert: "New Ticket Added",
sound: "default"
}
},{
success: function(){
response.success('true');
},
error: function (error) {
response.error(error);
}
});
});
此代码向所有用户发送推送.
This code sends push to all users.
请帮忙
推荐答案
这可以是一个解决方案:
Parse.Cloud.afterSave( "Ticket", function(request) {
//Get value from Ticket Object
var username = request.object.get("username");
//Set push query
var pushQuery = new Parse.Query(Parse.Installation);
pushQuery.equalTo("username",username);
//Send Push message
Parse.Push.send({
where: pushQuery,
data: {
alert: "New Ticket Added",
sound: "default"
}
},{
success: function(){
response.success('true');
},
error: function (error) {
response.error(error);
}
});
});
这篇关于解析从云代码向特定用户发送推送通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!