Passbook-ruby gem for Rails

November 5, 2012 Andrei Dinin

I’m sure many of you are aware of the new Passbook app that came with iOS6. It is a very convenient and centralized way to keep all of your cards and passes in one spot. Passes can be updated by the vendor in case anything changes (ie. gate number, point balance). Passes can also be associated with your existing app.

The design of the user interaction in Passbook is simple and refined. Apple hid all the implementation details so that the average user isn’t exposed to the complexity, even my grandma can use it (if she ever saw an iPhone). With that said, there are still a couple of gotchas for iOS developers. We’re sharing our solution (and source code) to help you get a quick start.

Implementing Passbook on the server is simple to start with. At the same time, it is easy to overlook details. It is easy to underestimate the time it will take to implement and deploy a solid and scalable solution for Passbook.

The sample code that Apple provides is very helpful, but as you ease into it and believe that it solved all your problems, you might overlook your unique requirements. One issue we faced involved the file system. The sample code writes to the file system and then sends the file from the file system. With the amount traffic we got, we needed a cleanup task and we were killing the IO. We rewrote the signing part of the code to hold everything in memory instead and wiped out all the file system worries in one sweep. I was overjoyed with deleting so much code.

Furthermore, we are releasing a ruby gem that handles this problem and lets you get a head start. We have learned from these issues so you don’t have to make the same mistakes.

The passbook-ruby gem not only manages and signs your pkpass file, but it manages all the extra routes you actually have to implement on your server. In essence, its a signing utility and a web service in one. You have to keep in mind that all those passes you are distributing will want to register with your server. They will unregister as soon as someone deletes them from the Passbook app. Passbook-ruby gem manages all of this for you using the best practices.

We use a template approach, where you design a static template of your pass package. You get to dynamically update some of the JSON in the model we generate for you (see update_pass method in the generated model). There is a sample code that does that. You leave the pass.json (along with other files) unzipped in a folder (preferably in #{Rails.root}/data/templates/pass.your.pass). Of course, you can override the functionality, but we are already exposing a few methods for customization.

If you already have your certificates in order, it shouldn’t take you more than a few minutes to deploy a Passbook project. Give it a try with our tutorial.

(If you don’t have the certificates, follow the P12 and WWDR Certificate process)

About the Author


More Content by Andrei Dinin
The New York Times Maps the Many Roads to the White House
The New York Times Maps the Many Roads to the White House

With only hours to go until the American people elect the next President of the United States, prognosticat...

Whether 1D or 2D, Barcode Scanning – A Revolution Not To Be Ignored
Whether 1D or 2D, Barcode Scanning – A Revolution Not To Be Ignored

Although barcode scanning has formerly only been used in industrial uses, the rise of smartphones changed t...

Enter curious. Exit smarter.

Register Now