Reputation: 117
Notification Using Parse from Server. I have to send different message for a set of users
like,
you got 1st rank - to User A
you got 2nd rank - to User B
you got 3rd rank - to User C
In Parse, i have save the rank details for each users like
device_id userA rank1
device_id userB rank2
device_id userc rank3
While pushing the message, i have the send the message with the rank value
url = 'https://api.parse.com/1/push'
message = 'you got Xth rank'
data = {:data => message}.to_json
HTTParty.post(url,:body => data)
I can able to send the static message with the above code. But how to send the message with dynamic values from parse database of respective record.
Upvotes: 0
Views: 167
Reputation: 522
Looping through users and sending them push one by one may be the solution to your problem, Here is an example code in JS
var installationQuery = new Parse.Query(Parse.Installation);
installationQuery.each(
function(result) {
var tempQuery = new Parse.Query(Parse.Installation);
tempQuery.equalTo("username", result.get('username'));
// Send push notification to query
Parse.Push.send({
where: tempQuery,
//
data: {
alert: "Hey "+result.get('name')+" your Rank ."+ result.get('rank')
}
}, {
success: function() {
response.success("Pushed to "+result.get('name'));
},
error: function(error) {
// Handle error
response.success("Error in push to"+result.get('name'));
}
});
},
{
success: function(result) {
console.log("push sent to all users.");
response.success();
},
error: function() {
} }
);
And if your data for ranks isn't in installation e.g. it's in Users Table then your first query would be on Users table and in function on each to send push you second query will remain on installation table.
Any query?
Upvotes: 1