Start a new topic

How do I send push notifications?

I've successfully registered my device using my client library. How do I send push notifications to my device?
1 Comment

There are two ways to send push via business logic, depending whether or not you want to send a single, static message to everyone, or a custom message to each user. Below are examples for both.



### Static message



var push = modules.push;



db.attendees.find({event_id:"OneEventId"}, function(err, result) {

if (err) {

response.error(err);

} else {

message = "Hello!";

push.sendMessage(result, message);

}

});



### Custom Message



var async = modules.async;

var push = modules.push;



// Utilizes Async module for iterating through users

var iterator = function(item, cb) {

// do something to create the message for a specific user

var message = "Hello " + user.username;

push.sendMessage(item, message);

cb(null);

}



var callback = function(err) {

if (err) {

response.error(err);

} else {

response.complete(200);

}

};

db.attendees.find(event_id:"OneEventId", function(err, result) {

if (err) {

response.error(err);

} else {

async.each(result, iterator, callback);

}

});
Login or Signup to post a comment