我正在尝试使用PFInstallation Query发送推式通知,该通知将发送给与PFQuery匹配的用户。解析服务器日志显示该通知已发送,但没有人收到。 for (i = 0; i < response.results.length; i++) {
for (var acd = 0; acd < response.results[i].address_components.length; acd++) {
var fff = response.results[i].address_components[acd];
var storableLocation;
if(fff.types.includes("neighborhood")) {
storableLocation = fff.long_name;
}else if (fff.types.includes("sublocality_level_1")){
storableLocation = fff.long_name;}}}
console.log(storableLocation) gives result - London.
始终为零,尽管有些用户与PFQuery匹配。代码如下。
云代码
pushQuery
电汇代码
Parse.Cloud.define("providerPush", function(request, response) {
var expDate = new Date();
expDate.setDate(expDate.getDate() + 1);
var data = {"badge": "Increment", "sound": "default"};
data['alert'] = request.params.message;
var userGeo = request.params.location;
const providerQuery = new Parse.Query("ProvidersOnline");
providerQuery.withinKilometers("location", userGeo, 2.5);
providerQuery.equalTo("fulfilling", false);
providerQuery.find();
var pushQuery = new Parse.Query(Parse.Installation);
pushQuery.matchesQuery("username", providerQuery);
pushQuery.find({useMasterKey: true }).then(function(results) {
console.log("Success");
console.log(results);
response.success(results);
}, function (error) {
console.log("Error");
console.log(error);
response.error(error);
});
Parse.Push.send({
where: pushQuery,
data: data,
expiration_time: expDate
},{
success: function () {
response.success("Pushed successfully");
},
error: function (error) {
response.error(error);
},
useMasterKey: true
});
});