-
Handling iOS push notification with NodeJS
Posted by Samser Alam | Last Updated: 10-Jan-17
Following steps to implement apns notification for iOS.
1. Get the device token.
2. Install npm
npm install apns
3. simple code here.var options = {
"pfx": "Certificate",
"gateway": "gateway.sandbox.push.apple.com",
"passphrase": "xyz",
"port": 2195,
"enhanced": true,
"cacheLength": 5
}
var myDevice = new apn.Device("Device Token);options.errorCallback = apnError;
var apnConnection = new apn.Connection(options);
var data = new apn.Notification();data.device = myDevice;
data.expiry = Math.floor(Date.now() / 1000) + 3600; // Expires 1 hour from now.
data.badge = 1;
data.sound = "ping.aiff";
data.alert = payload.message;
data.contentAvailable = 1;
data.payload = {
'message': "message",
'title': "title"
};
if (apnConnection) {
apnConnection.pushNotification(data, myDevice);
}
} catch (err) {
console.log('Error in sending apnPushNotification', err);
}Thanks.