我想在Parse.com上发送带有Cloudcode的推送通知。
推送通知应发送给订阅特定频道并触发服务的所有Android设备。
答案 0 :(得分:4)
您只需要一个安装查询,以及随附的推送。例如:
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");
}
});
该安装查询可以是基于渠道的查询,您可以为文件中提供的推送查询制定其他规范:
答案 1 :(得分:4)
您不需要查询来向频道发送推送。只需调用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)
}
});
请务必不要在频道名称中使用空格和大写字母。该频道不会添加到后端的订阅频道中。
答案 2 :(得分:1)
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));
}
});