Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send Push Notifications with Parse.com Cloudcode

I want to send a Push Notification with Cloudcode on Parse.com.

The push notification should be sent to all android devices that are subscribed to a specific channel and trigger a service.

like image 658
Janusz Avatar asked Feb 14 '26 08:02

Janusz


2 Answers

All you need is an installation query, along with an accompanying push. For example:

var pushQuery = new Parse.Query(Parse.Installation);
pushQuery.containedIn("user", userlist);
Parse.Push.send({
  where: pushQuery, 
  data: {
     alert: "Your push message here!"
  }
}, {
  success: function() {
    response.success("pushed");
  }, error: function(error) {
   reponse.error("didn't push");
  }
});

That installation query can be a query based on a channel, and there are other specifications you can make for the push query, given in the documentation:

Parse Docs

like image 115
BHendricks Avatar answered Feb 15 '26 22:02

BHendricks


You don't need a query to send a push to a channel. Just call Parse.Push.send and add a channel array to the data object.

Parse.Push.send({
        channels: [ "channel_name" ],
        data: {
            alert: "Alert message"
        }
    }, {
        success: function () {
            response.success("Push was sent");
        },
        error: function (error) {
            response.error("Could not send push " + error)
        }
    });

Be sure to not use spaces and Capital letters in channel names. The channel will not be added to the subscribed channels in the backend.

like image 44
Janusz Avatar answered Feb 15 '26 20:02

Janusz