Handling iOS push notification with NodeJS
Posted By : Samser Alam | 06-Jan-2017
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.
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Samser Alam
Samser is a bright java developer and have knowledge of Core Java, J2EE, C , C++. He can work over Netbeans and myeclipse. and he loves to play cricket.