【发布时间】:2015-09-07 06:49:47
【问题描述】:
我已将所有用户的位置保存在安装对象中。我还有另一个名为 locationObject 的对象,当当前用户发送他的当前位置时它会更新。当它这样做时,我想将他的当前位置与所有其他保存的位置进行比较,并向附近的用户发送推送通知。这是我的代码,但这似乎不起作用。
//this code should run when the locationObject is updated
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);
pushQuery.find({
success: function(results) {
if (results.length > 0) {
//console.log(JSON.stringify(results));
for (i = 0; i < results.length; 1++) {
Parse.Push.send({
where: pushQuery,
data: {
alert: "some user is nearby"
}
}, {
success: function() {
console.log("push was successfull")
},
error: function(error) {
console.log("sending push failed")// Handle error
}
});
}
} else {
console.log("failure");
}
},
error: function (error) {
console.log("error");
}
});
});
【问题讨论】:
-
我可以看到一些问题 - 您的循环中有
1++而不是i++,您正在执行查询并将其包含在您的推送中,并且您没有使用来自您的查询/循环 - 要么简单地将pushQuery包含在您的推送中,要么使用结果生成单独的推送消息。 -
感谢您的指导。
标签: ios parse-platform geolocation