Rails 3 and apn_sender
I also worked on the apn_sender problem because I like that Apple Push Notification support seems pretty reliable. However, the project was abandoned, and now it is behind the last rails of series 3. I got the system to work as follows.
Gemfile
gem 'apn_sender', :require => 'apn' gem 'daemons' gem 'resque', '1.20.0' gem 'resque-access_worker_from_job'
Signal processing has changed in Resque after 1.20, so you should use the older 1.20.0. Demons were supposed to be requirements all the time, but were never explicitly specified in the specification of gems.
script / apn_sender
#!/usr/bin/env ruby
Got it from here. The reason the apn_sender script is not being generated is because the script generator needs to be updated for the 3 series of rails.
Sender Launch
./script/apn_sender
When you start the environment, you probably need the production value, since ad_hoc and release versions use the production certificate.
This fork on github fixed some problems with rails 3, but the problem with resque problem still needs to be resolved explicitly.
Manual testing
This website shows how to send messages bypassing the daemon. It stores markers as base64 encoded strings, which are nice and compact. The device string format in the apn_sender structure is a hexadecimal string, formatted as follows: deadbeef 0a1b2cdf deadbeef 0a1b2cdf deadbeef 0a1b2cdf deadbeef 0a1b2cdf . Seats are optional.
require 'base64' ios_device_token = User.where(username: 'Cameron').first.ios_device_token token = Base64.decode64(ios_device_token).unpack('H*').first.scan(/\w{8}/).join(' ') notification = APN::Notification.new(token, { alert: 'Hello, World!', sound: true, badge: 99 }) sender = APN::Sender.new(verbose: true, environment: 'production') sender.send_to_apple(notification)
Make sure feedback.rb is updated.
# Unpacking code borrowed from http://github.com/jpoz/APNS/blob/master/lib/apns/core.rb while bunch = socket.read(38)
There was no 38 in one version of the code, and this led to the fact that bad token strings were returned from the feedback service
RubyMine by JetBrains
If you plan to take Ruby development to the next level, you should also consider an IDE, such as RubyMine , because it makes everything a lot easier.