Я пытаюсь отправить push-уведомление с помощью PFInstallation Query, которое отправит пользователям, которые соответствуют PFQuery.Журнал Parse-сервера показывает, что уведомление отправлено, но никто его не получает.pushQuery
постоянно равен нулю, хотя есть пользователи, которые соответствуют PFQuery.Код выглядит следующим образом.
КОД ОБЛАКА
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
});
});
КОД SWIFT
//SEND PUSH TO PROVIDERS
let orderQuery = PFQuery(className: "ProvidersOnline")
orderQuery.whereKey("location", nearGeoPoint: self.location, withinKilometers: 2.5)
orderQuery.whereKey("fulfilling", equalTo: false)
//orderQuery.order(byAscending: "createdAt")
orderQuery.findObjectsInBackground(block: {(objects, error) -> Void in
print("PROVIDER PUSH QUERY")
print(objects?.count)
print(error)
if objects?.count != 0 && error == nil {
print("PROVIDER PUSH SENT")
if let objects = objects {
for object in objects {
print("order query objects are")
print(objects)
print("order query done")
let vehicle = object["location"] as! PFGeoPoint
let distance: Double = self.location.distanceInKilometers(to: vehicle)
let format = ".1"
// Send push notification to query
let pushMessage = "Someone requested a ride \(distance.format(format)) km away!"
PFCloud.callFunction(inBackground: "providerPush", withParameters: ["message": pushMessage, "location": vehicle]) { (success, error) -> Void in
if error != nil {
print("error is not nil")
print(error!)
} else {
print("push success")
print(success!)
}
}
}
}
}
})