APN on Rails 0.3.0 Released
The latest version of Apple Push Notifications on Rails (APN on Rails) has been released. This release brings a few bug fixes, a new migration, and Feedback processing.
Installing/upgrading is easy:
$ sudo gem install apn_on_rails
$ ruby script/generate apn_migrations
$ rake db:migrate
It’s important to always run the migrations generator after each update to get the latest database schema needed for the the gem.
To use the new Feedback integration you have to first make sure that you update the new last_registered_at column when your iPhone application calls home. This column is checked against the timestamp Apple returns with the device token. If the last_registered_at is older than Apple’s date then the device is deleted, otherwise the Feedback is ignored.
To get and process the list of devices from Apple’s Feedback service just run the following Rake task:
$ rake apn:feedback:process
Enjoy!
Tags: apn, apple, gem, iphone, push notification, rails, release

August 12th, 2009 at 10:18 am
Hey Mark,
Thanks a lot for your work on this gem. I’m trying to get it to run alongside my current Rails backend (which already has a devices model, etc.) However my first problem is that I can’t get the Rake tasks to run. I’ve followed the README and created an example notification via the console with no problem.
But rake apn:notifications:deliver, just returns:
rake aborted!
uninitialized constant APN
Any idea of the problem?
Thanks and take care,
Russell.
August 12th, 2009 at 10:23 am
Hey Russell, did you add the following to your Rakefile:
begin
require ‘apn_on_rails_tasks’
rescue MissingSourceFile => e
puts e.message
end
Can you also run the task with the –trace option and send me the stack trace, that should help point out where the problem is.
Thanks.
August 12th, 2009 at 10:48 am
Hey,
Thanks for the quick reply. I’ve added the necessary require to my Rakefile.
Trace dump is:
** Invoke apn:notifications:deliver (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute apn:notifications:deliver
rake aborted!
uninitialized constant APN
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.2/lib/active_support/dependencies.rb:443:in `load_missing_constant’
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.2/lib/active_support/dependencies.rb:80:in `const_missing’
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.2/lib/active_support/dependencies.rb:92:in `const_missing’
/Library/Ruby/Gems/1.8/gems/apn_on_rails-0.3.0/lib/apn_on_rails/tasks/apn.rake:7
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in `call’
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in `execute’
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in `each’
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in `execute’
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:597:in `invoke_with_call_chain’
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/monitor.rb:242:in `synchronize’
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:590:in `invoke_with_call_chain’
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:583:in `invoke’
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2051:in `invoke_task’
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `top_level’
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `each’
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `top_level’
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling’
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2023:in `top_level’
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2001:in `run’
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling’
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:1998:in `run’
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/bin/rake:31
/usr/bin/rake:19:in `load’
/usr/bin/rake:19
August 12th, 2009 at 10:54 am
Sounds like you’re missing:
require ‘apn_on_rails’
I have mine at the bottom of environment.rb.
Let me know if that works for you.
August 12th, 2009 at 11:10 am
Bingo! I had mine in ApplicationController. Thanks Mark, after swapping Rails for Objective C for the last 12 months, I’m a little rusty getting back into it.
Thanks for you help with this problem and thanks for wrapping up all this in your gem. The test now worked!
Russell
August 12th, 2009 at 11:14 am
Glad I could help.
You’ll have to let me know when you’re app is released.
August 12th, 2009 at 1:23 pm
So, I have one suggestion!
It would be great to fix a limit on the number of notifications that the rake task processes per call. In my case, the notifications are to alert users that a new download is available. I want to spread these out over a certain time period to avoid server load spikes.
Russell
August 12th, 2009 at 1:26 pm
That sounds like a reasonable request. My I suggest forking it, and adding it?
http://github.com/markbates/apn_on_rails/tree/master
I would set a configatron setting for it, but have it overridable with an ENV param into the Rake task.
If you do it, I’d quite happily merge it back in.
August 12th, 2009 at 1:42 pm
Ok, I’ll look into this tomorrow (UTC+2). Thanks Mark.
Russell.
August 13th, 2009 at 8:33 am
So, I’m now actually using two queues to deal with my subscription publishing queue and the throttling is actually done in the first one, so I haven’t made any changes to APN on Rails. Sorry
I’ll be sure to add a credit to you in the app. Thanks again Mark.
September 27th, 2009 at 6:00 pm
Hey Mark!
So, the app is released now, but I’m having major problems with the apn:feedback:process rake task. It’s iterating over around 2,500 devices that we have registered for notifications, but consumes huge amounts of memory and ends up crashing Apache :-/
Russell.
September 29th, 2009 at 4:33 am
Hello again,
I took a look at the code from Git Hub and maybe the issue was that the Apple feedback service was down, or there was a problem with it in some way? Could you see a possibility that erroneous data could cause the process to spiral out of control?
Feel free to contact me by e-mail as there’s no comment notification for this blog.
Thanks,
Russell.
December 1st, 2009 at 10:17 am
Hi Mark,
Thanks for apn_on_rails. It’s been a big help. I’d like to include a custom property in some of my notification payloads and I can’t see a way to do that in apn_on_rails without modifying the gem code. Is this my best option?
Thanks.
December 1st, 2009 at 10:28 am
Hi Rebecca, yeah, that’s something I missed in the first pass. Someone submitted a patch for it a while back, but I don’t take patches without tests. The best, and easiest way to add it, is to fork the gem on GitHub, make the changes and build the gem. If you add tests and send me a pull request, I’d be more than happy to pull them back into the main project.
On a side note, I’m actively looking for a maintainer of the library, as I no longer have the time to maintain it, and I don’t write iPhone apps anymore.
Hope that helps.
December 1st, 2009 at 1:06 pm
Hi Mark, I’m following your suggestion and forking the project on GITHub. Would you be willing to share the patch you received earlier? You can send it to me by email (I assume you have access to commenter email addresses…). Once I get it working and add tests I’ll send a pull request. Depending on how this goes, I and my organization may be able to take on maintaining the library.
Thanks!
January 4th, 2010 at 7:51 pm
I would also like to put in custom properties so that I can tell the App which page to open. Rebecca / Mark: any leads on this?