Coder Social home page Coder Social logo

node-apn-server's Introduction

Purpose:

Provide an http based API that you can send POST requests to and it will send a push notification to apple's notification service.

Prerequisites

Goal Usage:

 node app.js
 curl -d "appId=<your-app-id>&appSecret=<your-app-secret>&deviceToken=760ff5e341de1ca9209bcfbd320625b047b44f5b394c191899dd5885a1f65bf2&notificationText=What%3F&badgeNumber=4&sound=default&payload=5+and+7" http://localhost:3000/

Getting Started:

  • Start couchdb
  • Create a node_apn database in couch
  • Create the pre-requisite data needed to support the server
  • Add the couch_views/users_all.js content as a view called "_design/users" with the name "all"
  • Add the couch_views/applications_secrets.js content as a view called "_design/applications" with the name "secrets"
  • Add a user document and configure that user's applications
  • There is an example document with one user and one application configured shown below
  • Pay attention to the certData and keyData entries in the settings hash, the server currently provides a way for you to upload the certificate and key, but it's ugly. The plan is to possibly use a different front end to manage the things that might be easier to do in a blocking environment.

--

 git clone [email protected]:adamvduke/node-apn-server.git
 cd node-apn-server
 npm install
 node app.js

Example Document:

 {
  "_id": "0aead832d8a8e5f57e0c10b5ff000565",
  "_rev": "11-92625b691c7e8203250de95fea65ada2",
  "username": "adamvduke",
  "password": "password",
  "type": "user",
  "applications": [
   {
    "app_id": "1",
    "app_secret": "1",
    "settings": {
                 "certData": "Your Cert Data goes here",
                 "keyData": "Your Key Data goes here",
                 "gateway": "gateway.push.apple.com",
                 "port": 2195,
                 "enhanced": true,
                 "cacheLength": 5
                }
   }
  ]
 }

Sending Notifications:

There are three required parameters:

  • appId - Your application's appId
  • appSecret - Your application's appSecret
  • deviceToken - The device token to send the notification to

Optional parameters are:

  • notificationText - The text that will display on the device.
  • badgeNumber - The value of the badge to be set on the application's icon.
  • sound - The sound to be played with the notification
  • payload - Extra data to included in the notification, formatted as a json dictionary
  • Passed in the options dictionary, with the key: info, during -application:didFinishLaunchingWithOptions:

Certificates:

  • Do the dance to get the production push notification certificate from the iOS provisioning portal
  • Download and install the certificate into Keychain Access.app
  • Export the certificate and private key separately as apns-prod-cert.p12 and apns-prod-key.p12 respectively
  • For both exports, you will be asked to specify a password, then asked for your keychain password. Do not specify a password on the first prompt.
  • Run the following commands to convert the certificate and private key to .pem format

--

openssl pkcs12 -clcerts -nokeys -out apns-prod-cert.pem -in apns-prod-cert.p12
openssl pkcs12 -nocerts -out apns-prod-key.pem -in apns-prod-key.p12

You will be forced to set a PEM passphrase on the second command, so execute the following command to remove it:

openssl rsa -in apns-prod-key.pem -out apns-prod-key-noenc.pem

See this blog entry for more details on setting up the certificates.

Credits:

node-apn-server's People

Contributors

adamvduke avatar

Watchers

mntz avatar James Cloos avatar  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.