【发布时间】:2026-01-24 12:30:01
【问题描述】:
我在Parse Cloud Code 中使用的Parse.Push 上找不到任何文档。我看到的用例是这样的……
// Send the push notification to results of the query
Parse.Push.send({
where: pushQuery,
data: {
alert: message
}
}).then(function() {
response.success("Push was sent successfully.")
}, function(error) {
response.error("Push failed to send with error: " + error.message);
});
如果收件人用户设置了通知(即有一个有效的安装实例,与他们的用户相关联),我想要做的是发送一个推送通知。
目前我创建查询并使用 pushQuery 将其传递到上面。我注意到在 Parse 仪表板中创建了一个推送,但发送的推送为 0。
真的,如果用户存在,我只想创建推送。我已经创建了查询,并且可以运行它并在我得到结果时返回......
Parse.Cloud.define("sendTurnNotificationToUser", function(request, response) {
var senderUser = request.user;
var recipientUserId = request.params.recipientId;
var message = request.params.message;
// Validate the message text.
// For example make sure it is under 140 characters
if (message.length > 140) {
// Truncate and add a ...
message = message.substring(0, 137) + "...";
}
// Send the push.
// Find devices associated with the recipient user
var recipientUser = new Parse.User();
recipientUser.id = recipientUserId;
var pushQuery = new Parse.Query(Parse.Installation);
pushQuery.equalTo("user", recipientUser);
pushQuery.find({
success: function(results) {
response.success("push user lookup was ok");
response.success(results);
},
error: function() {
response.error("push user lookup failed");
}
});
我可以将 Parse.Push.send 调用添加到查询成功。但是 Parse.Push.send 有一个 where 子句,我不知道那里需要什么?我不想运行查询两次。
【问题讨论】:
标签: ios parse-platform parse-cloud-code