-
-
Save argon/b781f31d23eb4c215f70 to your computer and use it in GitHub Desktop.
node-apn #188
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ 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