apns-http2
v1.0.6
Published
This module provides wrapper to send push notification based on HTTP/2 protocol
Downloads
276
Readme
APNS2
To use this library, node must be v6 or higher.
Installation
npm install apns-http2
Create Client
Client using .p12 and passphrase
const APNS = require('apns-http2');
const fs = require('fs');
const apnsClient = new APNS({
pfx: fs.readFileSync('/path/to/Certificates.p12'),
passphrase: 'test',
apns_topic: 'com.yourapp.com',
production: false
});
Client using cert and key in .pem extension
const APNS = require('apns-http2');
const fs = require('fs');
const apnsClient = new APNS({
cert: fs.readFileSync('/path/to/Certificate.pem'),
key: fs.readFileSync('/path/to/key.pem'),
apns_topic: 'com.yourapp.com',
production: false
});
Sending Push Notification
const Notification = APNS.Notification;
const aps = {
badge : 9,
sound : "bingbong.aiff"
};
const alert = {
title : "Game Request",
body : "Bob wants to play poker"
};
const deviceToken = '00fc13adff785122b4ad28809a3420982341241421348097878e577c991de8f0';
const options = {
'aps' : aps,
'alert' : alert,
'priority' : 10,
'expiration' : 0
}
const notification = new Notification(deviceToken, options);
apnsClient.send(notification)
.then((res) => {
console.log("response: ");
console.dir(res);
}).catch((err) => {
console.log('APNS ERROR: ' + err);
});