如何传递触发推送通知的用户对象
How to pass the user object that triggered the push notification
我已经在安装对象中保存了所有用户的位置。我有另一个名为 locationObject 的对象,当当前用户发送他的当前 location.When 时它会更新,云代码将他的当前位置与所有其他保存的位置进行比较,并向 [=16] 的用户发送推送通知=] 是我生成推送通知的代码。
Parse.Cloud.afterSave("locationObject", function (request) {
var geoPoint = request.object.get("myCurrentLocation");
var pushQuery = new Parse.Query(Parse.Installation);
pushQuery.near("significantLocationUpdate", geoPoint);
pushQuery.limit(100);
Parse.Push.send({
where: pushQuery,
data: {
alert: "some user is nearby"
}
}, {
success: function() {
console.log("push was successful");
},
error: function(error) {
console.log("sending push failed")// Handle error
}
});
});
现在,我的问题是,我如何将触发推送通知的用户对象连同他的当前位置传递给我要向其发送推送通知的用户?
您可以将additional data添加到推送中。例如:
data: {
alert: "some user is nearby",
user: [user objectId],
latitude: [user latitude],
longitude: [user longitude]
}
我已经在安装对象中保存了所有用户的位置。我有另一个名为 locationObject 的对象,当当前用户发送他的当前 location.When 时它会更新,云代码将他的当前位置与所有其他保存的位置进行比较,并向 [=16] 的用户发送推送通知=] 是我生成推送通知的代码。
Parse.Cloud.afterSave("locationObject", function (request) {
var geoPoint = request.object.get("myCurrentLocation");
var pushQuery = new Parse.Query(Parse.Installation);
pushQuery.near("significantLocationUpdate", geoPoint);
pushQuery.limit(100);
Parse.Push.send({
where: pushQuery,
data: {
alert: "some user is nearby"
}
}, {
success: function() {
console.log("push was successful");
},
error: function(error) {
console.log("sending push failed")// Handle error
}
});
});
现在,我的问题是,我如何将触发推送通知的用户对象连同他的当前位置传递给我要向其发送推送通知的用户?
您可以将additional data添加到推送中。例如:
data: {
alert: "some user is nearby",
user: [user objectId],
latitude: [user latitude],
longitude: [user longitude]
}