node.js - How to implement APNS notifications through nodejs? -


Is there any good NPM module to implement Apple PUSH notifications? A simple example would be great.

I found that the solution is low which uses the apn module.

  var requires apn = ('APN'); Var ca = ['entrust_2048_ca.cer']; / * Option of option * / var option = {certificate: 'path to yuour cert.pem', key: 'path to your key', ca: ca, passphrase: 'your passphrase', output: true, connection timeout: 10000}; Var apnConnection = new apn.Connection (option); / * Device * / var deviceToken = 'your device token'; Var myDevice = new apn.Device (deviceToken); / * Notification * / var Note = New apn.Notification (); Note.expiry = Math.floor (date now () / 1000) + 3600; // 1 hour expiration from now on Note.badge = 3; Note: payload = {'message': 'Hi there'}; ApnConnection.pushNotification (note, myDevice);  

If you have to use the APIs feedback service to stop sending notifications to the device, which is not able to obtain it (the application is uninstalled), then you can add the following :

   

You can use the following to handle various events related to the connection:

  apnConnection.on ('connect', function ( Open sockets) {//}); ApnConnection.on ('Error', function (error) {//}); ApnConnection.on ('transmitted', function (information, device) {//}); ApnConnection.on ('Transmission error', function (errCode, notification, tool) {//}); ApnConnection.on ('drain', function () {//}); ApnConnection.on ('timeout', function () {//}); ApnConnection.on ('Disconnect', Function (OpenSocket) {//}); ApnConnection.on ('socketError', console.error);  


Comments