Git Product home page Git Product logo

node-apns's Introduction

node-apns

This module is no longer maintened and deprecated in favor of node-apn.

Previously i used node-apn, but it revealed that it was not stable in case of big volumes, so i forked it, and finally i decided to create a completely new module. Since 1.2, node-apn was completely rewritten based on this fork, so i have re-switched to node-apn and i advice you to do the same.


How to use it ?

var apns = require("apns"), options, connection, notification;

options = {
   keyFile : "conf/key.pem",
   certFile : "conf/cert.pem",
   debug : true
};

connection = new apns.Connection(options);

notification = new apns.Notification();
notification.device = new apns.Device("iphone_token");
notification.alert = "Hello World !";

connection.sendNotification(notification);

Installation

Via npm:

 $ npm install apns

As a submodule of your project

$ git submodule add http://github.com/neoziro/node-apns.git apns
$ git submodule update --init

API

new Notification()

Create a notification to send throw a connection.

  • notification.payload : Notification payload.
  • notification.badge : The number on the badge.
  • notification.sound : The sound to use.
  • notification.alert : Alert text.
  • notification.device : The device where notification is sent.
  • notification.encoding : The encoding of the notification, default utf8. If you wish to send notifications containing emoji or other multi-byte characters you will need to set notification.encoding = 'ucs2'. This tells node to send the message with 16bit characters, however it also means your message payload will be limited to 127 characters.
var apns = require("apns"), notification;

notification = new apns.Notification();
notification.payload = {"description" : "A good news !"};
notification.badge = 1;
notification.sound = "dong.aiff";
notification.alert = "Hello World !";
notification.device = new apns.Device("iphone_token");

new Device(token)

The device where notification is sent.

  • token : The token in Buffer or string.
var apns = require("apns"), device;

device = new apns.Device("iphone_token");

new Connection(options)

Create a connection to open a socket and send notification.

Options avalaible are :

  • certData : Cert as Buffer.
  • keyData : Key as Buffer.
  • certFile : Path to the cert file (only if you don't use certData).
  • keyFile : Path to the key file (only if you don't use keyData).
  • passphrase : Passphrase used to connect.
  • gateway : Apple gateway, default gateway.push.apple.com.
  • port : Connection port, default 2195.
  • enhanced : Use enhanced mode to catch error, default true.
  • errorCallback : Error callback.
  • cacheLength : The number of notification to see if an error occur, if you don't know, let as default. Default 1000.
  • connectionTimeout : Time in ms before connection close, 10 minutes, is the time advised. Default 600000.
  • debug : Active debug mode (log main step to stdout), default false.
var apns = require("apns");

var options = {
   keyFile : "conf/key.pem",
   certFile : "conf/cert.pem",
   debug : true
};

var connection = new apns.Connection(options);

connection.send(notification)

Send a notification.

  • notification : The notification to send.
var apns = require("apns"), notification, options, connection;

options = {
   keyFile : "conf/key.pem",
   certFile : "conf/cert.pem",
   debug : true
};

connection = new apns.Connection(options);

notification = new apns.Notification();
notification.alert = "Hello World !";
notification.device = new apns.Device("iphone_token");

connection.sendNotification(notification);

Handling errors

If the enhanced binary interface is enabled and an error occurs when sending a message then subsequent messages will be automatically resent* and the connection will be re-established. If an errorCallback is also specified in the connection options then it will be invoked with 2 arguments.

  1. The error number as returned from Apple. This can be compared to the predefined values in the Errors object.
  2. The notification object as it existed when the notification was converted and sent to the server.

* N.B.: The cacheLength option specifies the number of sent notifications which will be cached for error handling purposes. At present if more than the specified number of notifications have been sent between the incorrect notification being sent and the error being received then no resending will occur. This is only envisaged within very high volume environments and a higher cache number might be desired.

License

MIT

node-apns's People

Contributors

gregberge avatar stardast avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.