Giter Club home page Giter Club logo

em-apn's Introduction

EM-APN - EventMachine'd Apple Push Notifications

We want:

  • Streamlined for a persistent connection use-case
  • Support for the enhanced protocol, with receipts

Usage

A simple interface is provided to just fire and forget:

require "em-apn"

EM.run do
  EM::APN.push(token, :alert => "Hello world")
end

Using this interface, the easiest way to configure the connection is by setting some environment variables so that EM::APN can find your SSL certificates:

ENV["APN_KEY"]  = "/path/to/key.pem"
ENV["APN_CERT"] = "/path/to/cert.pem"

Also, by default, the library connects to Apple's sandbox push server. If you want to connect to the production server, simply set the APN_ENV environment variable to production:

ENV["APN_ENV"] = "production"

This simple interface takes care of setting up and re-using a single, persistent connection to Apple's servers, and re-connects on demand if the connection is dropped.

It's also possible to create a connection manually, and currently, this is the only option if you want to attach a callback for data returned by Apple:

EM.run do
  @client = EM::APN::Client.connect(
    :key  => "/path/to/key.pem",
    :cert => "/path/to/cert.pem"
  )
  @client.on_receipt do |data|
    # Do something
  end

  # In some other callback
  notification = EM::APN::Notification.new(token, :alert => "Hello world")
  @client.deliver(notification)
end

In this example, we're explicitly setting the key, and cert with options to APN::Client.connect, but the environment variables mentioned above will work as well. Please keep in mind that Apple will close the connection whenever an error is returned, and APN::Client.closed? should be polled to check for disconnects.

Max Payload Size

Apple enforces a limit of 256 bytes for the entire payload.

We raise an EM::APN::Notification::PayloadTooLarge exception.

How you truncate your payloads is up to you. Be especially careful when dealing with multi-byte data.

TODO

  • Support the feedback API for dead tokens

Inspiration

Much thanks to:

em-apn's People

Contributors

daveyeu avatar cmdrkeene avatar jpignata avatar

Stargazers

Angus H. avatar Jim Chang avatar

Watchers

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