I want to send a Push Notification with Cloudcode on Parse.com.
The push notification should be sent to all android devices that are subscribed to a specific channel and trigger a service.
I want to send a Push Notification with Cloudcode on Parse.com.
The push notification should be sent to all android devices that are subscribed to a specific channel and trigger a service.
您所需要的只是一个安装查询以及随附的推送。例如:
var pushQuery = new Parse.Query(Parse.Installation);
pushQuery.containedIn("user", userlist);
Parse.Push.send({
where: pushQuery,
data: {
alert: "Your push message here!"
}
}, {
success: function() {
response.success("pushed");
}, error: function(error) {
reponse.error("didn't push");
}
});
该安装查询可以是基于通道的查询,并且您可以为推送查询制定其他规范,在文档中给出:
您无需查询即可向频道发送推送。只需调用Parse.Push.send并将通道数组添加到数据对象。
Parse.Push.send({
channels: [ "channel_name" ],
data: {
alert: "Alert message"
}
}, {
success: function () {
response.success("Push was sent");
},
error: function (error) {
response.error("Could not send push " + error)
}
});
确保不要在频道名称中使用空格和大写字母。该频道不会添加到后端订阅的频道中。
1) 添加
Parse.initialize("APPLICATION_ID", "JAVASCRIPT_KEY");
2) 在 Parse.com 中启用 Java 脚本推送通知
3)下载Java脚本项目“parse-js-blank”
4)使用Channel创建安装对象
5) 发送请求。
Parse.Push.send({
channels: [ "Giants","Vaquar" ],
data: {
alert: "Vaquar Alert Message."
}
}, {
success: function() {
// Push was successful
},
error: function(error) {
// Handle error
alert("(error"+eval(error));
}
});