I find myself living in two worlds these days. On one hand, I’m a web programmer writing centralized applications mostly with Rails. On the other hand, I’m an iPhone developer creating mobile applications. My iPhone apps live in my pocket; my web apps live on the ‘net.

Sometimes I want the best of both these worlds: mobile applications that periodically exchange data with their mother ship in the sky. In fact, one of my first iPhone apps was a companion to a Rails app that I’d built many years ago. Suddenly I had a way to access some of our small-business data while on the go. Then recently I started working on a new iPhone application that ended up needing a backend web app to share data with a larger community. Along the way, I hacked up a couple prototype applications just as learning opportunities.

I gave a tutorial on what I’ve learned at the 360iDev conference last week. The short version is that REST conventions make this type of integration a lot easier. For the longer version, I’ve posted the tutorial presentation and sample projects:

  • iPhone on Rails (PDF): This being an iPhone developer conference, I started with an overview of the REST conventions in Rails. Then, to get the iPhone app talking to the Rails app, I incrementally coded a solution starting with a simple, hand-rolled library and ending up using the excellent ObjectiveResource library. You kinda had to be there…

  • Expenses: A bare-bones, no-frills iPhone app that creates, reads, updates, and deletes a single resource (expenses) living in a scaffold-generated Rails app. It’s a simple example of how to use ObjectiveResource. I deliberately left out any bells and whistles so they didn’t get in the way of the fundamentals. (screenshot)

  • Budgets: Something a bit more realistic. This iPhone-Rails app combo manages budgets and their related expenses (nested resources). It also demonstrates a few techniques you’ll want to consider in your application, including asynchronous networking, authentication, and error handling. (screenshot)

Of course, you don’t have to use Rails or ObjectiveResource. Sometimes a JSON parsing library and a Sinatra app are a better fit. Or perhaps Django is more your style. The point is that conventions matter.

I thought I’d share these resources in the event they give you a jump-start on your next project.


iPhone Training: I hope you’ll join us for 4 full days of hands-on iPhone SDK training in Long Beach, CA on December 1-4. It’s a lot of fun!