Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@argon

argon/apn.js Secret

Last active August 29, 2015 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save argon/b781f31d23eb4c215f70 to your computer and use it in GitHub Desktop.
Save argon/b781f31d23eb4c215f70 to your computer and use it in GitHub Desktop.
node-apn #188
var apn = require("apn");
var token = "f932d5b1 7ec33c16 f10bd012 69793f80 f0877f12 014c2eb0 49a7caa1 bd142a78"; // iPad
if(token == "<insert token here>") {
console.log("Please set token to a valid device token for the push notification service");
process.exit();
}
var dev_dist = "dev";
var production = false;
if(dev_dist == "dist"){
production = true;
}
var options = {};
options.cert = __dirname + "/" + dev_dist + "/cert.pem";
options.key = __dirname + "/" + dev_dist + "/key.pem";
options.production = production;
console.log("Dev/Dist: ", dev_dist);
console.log(options);
var service = new apn.connection(options);
service.on("connected", function() {
console.log("Connected");
});
service.on("completed", function () {
console.log("Completed!");
});
service.on("transmitted", function(notification) {
console.log("Transmitted: ", notification);
});
service.on("socketError", function(err) {
console.log("Socket error", err.message);
});
service.on('transmissionError', function(err) {
console.log("Transmission Error", err);
});
service.on("error", function(err) {
console.log("Standard error", err);
});
function pushNotification() {
var note = new apn.notification().setAlertText("Hello");
service.pushNotification(note, token);
service.shutdown();
}
pushNotification();
$ tree
.
|____apn.js
|____dev
| |____cert.pem
| |____key.pem
|____dist
| |____cert.pem
| |____key.pem
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment