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.

 

 

About Author

Author Image
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.

Request for Proposal

Name is required

Comment is required

Sending message..