Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
121 lines (76 sloc) 4.22 KB


Please note this gem not yet used in production. If you want to help, please contact me.


Add to your GemFile

gem push-core

and add the push provider to you Gemfile:

For APNS (iOS: Apple Push Notification Services):

gem push-apns

For C2DM (Android: Cloud to Device Messaging, deprecated):

gem push-c2dm

For GCM (Android: Google Cloud Messaging):

gem push-gcm

And run bundle install to install the gems.

To generate the migration and the configuration files run:

rails g push
bundle exec rake db:migrate


The configuration is in the database and you add the configuration per push provider with the console (rails c):


Push::ConfigurationApns.create(:app => 'app_name', :connections => 2, :certificate =>"certificate.pem"), :feedback_poll => 60, :enabled => true).save


Push::ConfigurationC2dm.create(:app => 'app_name', :connections => 2, :email => "<email address here>", :password => "<password here>", :enabled => true).save


Push::ConfigurationGcm.create(:app => 'app_name', :connections => 2, :key => '<api key here>').save

You can have each provider per app_name and you can have more than one app_name. Use the instructions below to generate the certificate for the APNS provider.

Generating Certificates

  1. Open up Keychain Access and select the Certificates category in the sidebar.
  2. Expand the disclosure arrow next to the iOS Push Services certificate you want to export.
  3. Select both the certificate and private key.
  4. Right click and select Export 2 items....
  5. Save the file as cert.p12, make sure the File Format is Personal Information Exchange (p12).
  6. If you decide to set a password for your exported certificate, please read the Configuration section below.
  7. Convert the certificate to a .pem, where <environment> should be development or production, depending on the certificate you exported.

    openssl pkcs12 -nodes -clcerts -in cert.p12 -out <environment>.pem

  8. Move the .pem file into your Rails application under config/push.


To start the daemon:

bundle exec push <environment> <options>

Where <environment> is your Rails environment and <options> can be:

    -f, --foreground                 Run in the foreground.
    -p, --pid-file PATH              Path to write PID file. Relative to Rails root unless absolute.
    -P, --push-poll N                Frequency in seconds to check for new notifications. Default: 2.
    -n, --airbrake-notify            Enables error notifications via Airbrake.
    -F, --feedback-poll N            Frequency in seconds to check for feedback for the feedback processor. Default: 60. Use 0 to disable.
    -b, --feedback-processor PATH    Path to the feedback processor. Default: lib/push/feedback_processor.
    -v, --version                    Print this version of push.
    -h, --help                       You're looking at it.

Sending notifications

APNS: => 'app_name', device: '<APNS device_token here>', alert: 'Hello World', expiry:, attributes_for_device: {key: 'MSG'}).save

C2DM: => 'app_name', device: '<C2DM registration_id here>', payload: { message: 'Hello World' }, collapse_key: 'MSG').save

GCM: => 'app_name', device: '<GCM registration_id here>', payload: { message: 'Hello World' }, collapse_key: 'MSG').save

Feedback processing

The push providers return feedback in various ways and these are captured and stored in the push_feedback table. The installer installs the lib/push/feedback_processor.rb file which is by default called every 60 seconds. In this file you can process the feedback which is different for every application.

Rake Task

The push-core also comes with a rake task to delete all the messages and feedback of the last 7 days or by the DAYS parameter.

    bundle exec rake push:clean DAYS=2


  • Rails 3.2 +
  • Ruby 1.9


This project started as a fork of Ian Leitch RAPNS project. The differences between this project and RAPNS is the support for C2DM and the modularity of the push providers.

Jump to Line
Something went wrong with that request. Please try again.