Apple Push Notifications Toolkit for Ruby 11
Lately I’ve been working on an iPhone application that utilizes Push Notifications extensively. While Apple provides great documentation there is still a fair amount of work left up to the developer to send push notification in ordinance to their usage policy.
Since I’m using Rails for the backend I needed a way to maintain a single open SSL connection to prevent setup and tear down for every notification sent. To accomplish this I created an Event Machine based server deamon that that proxies all requests send by Rails application over a local, non SSL socket.
The proxy queues and sends each notification to the Apple notification servers. Additionally I’ve created a command line script to send notifications for testing purposes. My project Apn Server is hosted on Github.
You can add it to your Rails application via
config.gem "bpoweski-apnserver", :lib => 'apnserver',
:source => "http://gems.github.com"You can use either a direct connection to Apple or one through the apnserverd proxy included in the gem. To configure directly to Apple’s server (and also setting up and tearing down a new connection each time). Add the following to your environment.rb.
ApnServer::Config.pem = '/path/to/pem'
ApnServer::Config.host = 'gateway.push.apple.com'
ApnServer::Config.port = 2195To use the non SSL apnserverd proxy simply drop the PEM configuration option
ApnServer::Config.host = 'localhost'
ApnServer::Config.port = 22195To send a notification from Ruby
notification = ApnServer::Notification.new
notification.device_token = Base64.decode64(apns_token)
notification.alert = message
notification.badge = 1
notification.sound = 'default'
notification.pushYou can also send notifications via the line with
$ apnsend --server gateway.push.apple.com --port 2195 \
--pem key.pem \
--b64-token j92f12jh8lqcAwcOVeSIrsBxibaJ0xyCi8/AkmzNlk8= \
--sound default \
--alert Hello

Going to play with it, right away. Will post updates. Cool bit.
Trying to get this working on snow leopard, no luck whatsoever. Not sure what to do next… would GLADLY pay for help/code fix if that’s what’s necessary. No more hair to pull out…
/.gem/ruby/1.8/gems/eventmachine-0.12.10/lib/rubyeventmachine.bundle: [BUG] Segmentation fault ruby 1.8.7 (2009-06-12 patchlevel 174) [i686-darwin10.2.0]
Abort
Looks like some good work. Working with Apple iPhone Apps is a whole new challenge - and one I’m not brave enough to undertake yet, but I’m trying to get together some of the building blocks. I’ll add this to the list.
wow…..thanks this website gives the best information of Ruby. A very useful site for the software engineers who like to play around Ruby.
Going to play with it, right away. Will post updates. Cool bit.
Prudential West
Looks like some good work. Working with Apple iPhone Apps is a whole new challenge - and one I’m not brave enough to undertake yet, but I’m trying to get together some of the building blocks. I’ll add this to the list.
Wholesale Brand Name Clothing
wow…..thanks this website gives the best information of Ruby. A very useful site for the software engineers who like to play around Ruby.
Wholesalers
создам себе тоже бложег и буду там писать свои мысли
$ apnsend –server gateway.push.apple.com –port 2195 \ –pem key.pem \ –b64-token j92f12jh8lqcAwcOVeSIrsBxibaJ0xyCi8/AkmzNlk8= \ –sound default \ –alert Hello
Great idea!!!
Thanks a lot for sharing the rail application which helps me very much. Truly saying I was looking for this coding. I bookmark this site for further reading. Nice post.