0
votes

My app has notifications based on zip code and channels.

When a user changes zip code the app updates the Installation with the new zip.

In my beforeSave on Installation I grab the new zip and subscribed channels and search for relevant notifications.

Then I need to send the notifications as pushes back to that installation.

Two questions:

  1. Can I just push to the Installation object that came into the beforeSave as such:

    return Parse.Push.send({ where: request.object data: data })

or do I have to do an Installation query for that objectId?

  1. I can't just push the notification object. I need to configure the data. If there are multiple notifications (not likely but possible) what's the best way to send multiple pushes back to that installation (assuming I don't want to put them all in one push)?

I can't send the pushes from a for loop. Can I do something like this:

return notificationQuery.each().then( function(notification) { 
    //configure push from that notification
    return Parse.Push.send ... etc
})

Thanks!

1

1 Answers

0
votes

You can send Push notifications in parse based on channels or where(query) but not both.

So you can do a query on Installation class with channel and zipcode:

var query = new Parse.Query(Parse.Installation);
query.equalTo('channels', 'Indians');
query.equalTo('zipcode', "345678");

Parse.Push.send({
  where: query,
  data: {
    action: "com.example.UPDATE_STATUS"
    alert: "Ricky Vaughn was injured in last night's game!",
    name: "Vaughn",
    newsItem: "Man bites dog"
  }
}, {
  success: function() {
    // Push was successful
  },
  error: function(error) {
    // Handle error
  }
});

Hope this helps.