Blog

  • 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.

     

     

Tags: ios

View All PostsLeave a Comment
comments powered by Disqus

Mobile Applications

Video Content

Bigdata & NoSQL

SaaS Applications

Miscellaneous

Archives


Alexa Certified Site Stats for www.oodlestechnologies.com