Skip to content

Instantly share code, notes, and snippets.

@davideast
Last active April 20, 2021 17:19
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save davideast/b3fde097271a84a744a5 to your computer and use it in GitHub Desktop.
Save davideast/b3fde097271a84a744a5 to your computer and use it in GitHub Desktop.
Send push notifications with node-apn and Firebase
var apn = require("apn");
var Firebase = require("firebase");
var service = new apn.connection({ production: false }); // true for production pipeline
// Create a reference to the push notification queue
var pushRef = new Firebase("<your-firebase>.firebaseio.com/notificationQueue");
// listen for items added to the queue
pushRef.on("child_added", function(snapshot) {
// This location expects a JSON object of:
// {
// "token": String - A user's device token
// "message": String - The message to send to the user
// }
var notificationData = snapshot.val();
sendNotification(notificationData);
snapshot.ref().remove;
});
function sendNotification(notificationData) {
var notification = new apn.notification();
// The default ping sound
notification.sound = "ping.aiff";
// Your custom message
notification.alert = notificationData.message;
// Send the notification to the specific device token
service.pushNotification(notification, [notificationData.token]);
// Clean up the connection
service.shutdown();
}
@dac3971
Copy link

dac3971 commented Jun 4, 2016

Hi, I'm learning FCM - how can i do the same thing for Android?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment