samvermette.com

DEC 30, 2010

Simple APN Server

To never miss a gig, you definitely need to be notified of newly announced concerts. Shows 1.x had this, but it was flaky at best. And since I redesigned 2.0 from scratch, I took the opportunity to rewrite the whole APN server code as well.

PHP classes like php-apns and Ruby on Rails gems such as apn_on_rails and apnserver all will get you started for sending Apple Push Notifications (APNs). But they’re bloated as hell. APN_on_rails db migration, for example, creates 7 new tables in your database (for devices, groups, apps, notifications, etc.). That might be a fine setup for a huge webapp that processes a lot of synchronous notifications, but in my case, it seemed like overkill. And to be honest, I was curious to see how much code I could strip down. Here’s what I ended up with:

EDIT: RoR beast @pothibo just pointed out the APNS ror gem, which is pretty much what I was looking for from the start. But hey, at least now you know how it works!

Ruby

PHP (for old time sake)

Again, the idea here was to send a push notification in the most minimalist fashion. No handling of errors, no talking with Apple’s feedback service, or device tokens validation. Nada. If you’re actually looking to make the whole thing work, you’ll need to keep a couple more things in mind:


hello@samvermette.com