【发布时间】:2015-05-21 08:04:57
【问题描述】:
是否可以为任何时候通过 Parse 发送推送通知设置网络挂钩?
我想检索推送通知的详细信息,并针对推送通知发送到的任何设备设置一列
【问题讨论】:
标签: javascript parse-platform push-notification
是否可以为任何时候通过 Parse 发送推送通知设置网络挂钩?
我想检索推送通知的详细信息,并针对推送通知发送到的任何设备设置一列
【问题讨论】:
标签: javascript parse-platform push-notification
据我所知,没有任何挂钩,但您可以通过代码中的一个位置(客户端或云函数)运行所有推送,并在那里执行您想做的任何推送后工作。假设 JS 和高级定位,它可能看起来像这样:
function pushToInstallations(query, data) {
var params = { where: query, data: data};
return Parse.Push.send(params).then(function() {
// this is the interesting part, run the installation query
return query.find();
}).then(function(installations) {
var date = new Date();
// presumes underscore, but a regular for loop works too
_.each(installations, function(installation) {
installation.set("mostRecentPushDate", date);
});
return Parse.Object.saveAll(installations);
});
}
然后,无论您在代码中构建安装查询并调用 push 的任何位置,都改为调用新的 push 函数,如下所示:
var query = new Parse.Query(Parse.Installation);
query.equalTo('someColumn', someValue);
pushToInstallations(query, {alert: "some message"}).then(function(installations) {
// these installations passed back were pushed to and updated
}, function(error) {
// handle error
});
【讨论】: