0.1.4 • Published 8 years ago

node-pushnotifications-fixed v0.1.4

Weekly downloads
7
License
-
Repository
github
Last release
8 years ago

IMPORTANT: THIS IS A "FORK" FOR THE ORIGINAL REPO. I DON'T TAKE CREDIT OF TE WORK DONE BY DE APPFEEL TEAM. I JUST FIXED ONE BUG REGARDING THE APNS AND MADE A PULL REQUEST TO THE APPFEEL TEAM BUT THEY DIDN'T REPLAY AFTER 16 DAYS SO I NEED THIS LIBRARY ON NPM AND THAT'S WHY IM PUBLISHING A FIXED VERSION.

Node Push Notify

A Node.js module for interfacing with Apple Push Notification, Google Cloud Messaging, Microsoft Push Notification and Amazon Device Messaging services.

NPM Version

Installation

npm install node-pushnotifications

#Features

  • Powerful and intuitive.
  • Multi platform push sends.
  • Automatically detects destination device type.
  • Unified error handling.

Usage

iOS: Prepare cert.pem and key.pem as described in node-apn

Import and setup push module:

var settings = {
  gcm: {
    id: null, // PUT YOUR GCM SERVER API KEY,
    options: {},
    msgcnt: 1,
    dataDefaults: {
      delayWhileIdle: false,
      timeToLive: 4 * 7 * 24 * 3600, // 4 weeks
      retries: 4
    }
  },
  apn: {
    gateway: 'gateway.sandbox.push.apple.com',
    badge: 1,
    defaultData: {
      expiry: 4 * 7 * 24 * 3600, // 4 weeks
      sound: 'ping.aiff'
    }
  },
  adm: {
    client_id: null, // PUT YOUR ADM CLIENT ID,
    client_secret: null, // PUT YOUR ADM CLIENT SECRET,
    expiresAfter: 4 * 7 * 24 * 3600, // 4 weeks
  }
};
var push = new requiere('node-pushnotifications')(settings);

Define destination device ID. You can send to multiple devices, independently of platform, creating an array with different destination device IDs.

// Single destination
deviceIds = 'INSERT_YOUR_DEVICE_ID';

// Multiple destinations
deviceIds = [];
deviceIds.push('INSERT_YOUR_DEVICE_ID');
deviceIds.push('INSERT_OTHER_DEVICE_ID');

Next, create a JSON object witch MUST contain, at least, a title and message and send it to server.

data = {title: 'New push notification' , message: 'Powered by AppFeel', otherfields: 'optionally add more data');
push.sendPush(deviceIds, data, function (result) {
	console.log(result);
});

Result will contain 'true' or 'an error description'.

##Resources