This project is unmaintained. We recommend using a library compatible with Apple's newer HTTP/2-based API, such as apnotic.
A simple Ruby framework for sending push notifications and receiving feedback using the Apple Push Notification service
Add this line to your application's Gemfile:
gem 'apns_dispatch'
And then execute:
$ bundle
Or install it yourself as:
$ gem install apns_dispatch
connection = ApnsConnection.new(CERTIFICATE, production: true)
ApnNotification.new(connection, DEVICE_TOKEN, 'a message to a device').send_notification
Apple recommends periodically checking their feedback service for device tokens that have failed delivery. The feedback service also returns the time of the failure. If a device token was registered before the failure time, it should be removed from your system.
connection = ApnsConnection.new(CERTIFICATE, production: true, feedback: true)
ApnFeedback.new(connection).failed_device_tokens.each do |device_token, failure_time|
# Delete this device token from your system, if the registration time is before failure_time
end
If notifications are sent frequently, latency will be improved by reusing connections to the Push Notification service. ApnsDispatch also provides connection pooling:
# Initiates a new connection to the APNs
connection = ApnsConnectionPool.connection(CERTIFICATE, production: true)
# This will return the same connection, rather than initiating a new one
connection = ApnsConnectionPool.connection(CERTIFICATE, production: true)
apns_dispatch
requires Ruby 1.9+.
apns_dispatch
is written by Costa Walcott, and is Copyright 2012 SCVNGR, Inc. It is free software,
and may be redistributed under the terms specified in the MIT-LICENSE file.