If you know HTML, CSS, and JavaScript, you already have what you need to develop your own iPhone apps. With this book, you'll learn how to use these open source web technologies to design and build apps for both the iPhone and iPod Touch. Buy the print book or ebook or purchase the iPhone App.

Like millions of people, I fell in love with my iPhone immediately. Initially, web apps were the only way to get a custom app on the device, which was fine by me because I’m a web developer. Months later when the App Store was announced, I was jacked. I ran out and bought every Objective-C book on the market. Some of my web apps were already somewhat popular, and I figured I’d just rewrite them as native apps, put them in the App Store, and ride off into the sunset on a big, galloping pile of money.

Disillusionment followed. I found it difficult to learn Objective-C, and I was turned off by the fact that the language was of little use outside of Mac programming. Xcode and Interface Builder were pretty slick, but they weren’t my normal authoring environment and I found them hard to get accustomed to. I was infuriated by the hoops I had to jump through just to set up my app and iPhone for testing. The process of getting the app into the App Store was even more byzantine. After a week or two of struggling with these variables, I found myself wondering why I was going to all the trouble. After all, my web apps were already available worldwide—why did I care about being in the App Store?

On top of all this, Apple can—and does—reject apps. This is certainly their prerogative, and maybe they have good reasons. However, from the outside, it seems capricious and arbitrary. Put yourself in these shoes (based on a true story, BTW): you spend about 100 hours learning Objective-C. You spend another 100 hours or so writing a native iPhone app. Eventually, your app is ready for prime time and you successfully navigate the gauntlet that is the App Store submission process. What happens next?

You wait. And wait. And wait some more. We are talking weeks, and sometimes months. Finally you hear back! And...your app is rejected. Now what? You have nothing to show for your effort. The bubble.

But wait, it can get worse. Let’s say you do get your app approved. Hundreds or maybe thousands of people download your app. You haven’t received any money yet, but you are on cloud nine. Then, the bug reports start coming in. You locate and fix the bug in minutes, resubmit your app to iTunes, and wait for Apple to approve the revision. And wait. And wait some more. Angry customers are giving you horrible reviews in the App Store. Your sales are tanking. And still you wait. You consider offering a refund to the angry customers, but there’s no way to do that through the App Store. So you are basically forced to sit there watching your ratings crash even though the bug was fixed days or weeks ago.

Sure, this story is based on the experience of one developer. Maybe it’s an edge case and the actual data doesn’t bear out my thesis. But the problem remains: we developers have no access to Apple’s data, or the real details of the App Store approval process. Until that changes, building a native app with Objective-C is a risky proposition.

Fortunately, there is an alternative. You can build a web app using open source, standards-based web technologies, release it as a web app, and debug and test it under load with real users. Once you are ready to rock, you can use PhoneGap to convert your web app to a native iPhone app and submit it to the App Store. If it’s ultimately rejected, you aren’t dead in your tracks because you can still offer the web app. If it’s approved, great! You can then start adding features that enhance your web app by taking advantage of the unique hardware features available on the device. Sounds like the best of both worlds, right?

Who Should Read This Book

I’m going to assume that you have some basic experience reading and writing HTML, CSS, and JavaScript (jQuery in particular). I will be including some basic SQL code in Chapters 5 and 6, so a passing familiarity with SQL syntax would be helpful but is not required.

What You Need to Use This Book

This book is going to avoid the iPhone SDK wherever possible. All you’ll need to follow along with the vast majority of examples is a text editor and the most recent version of Safari (or better yet, WebKit, which is a more cutting-edge version of Safari that’s available for both Mac and Windows at You do need a Mac for the PhoneGap material in Chapter 7, Going Native, where I explain how to convert your web app into a native app that you can submit to the App Store.

Conventions Used in This Book

The following typographical conventions are used in this book:


Indicates new terms, URLs, email addresses, filenames, and file extensions.

Constant width

Used for program listings, as well as within paragraphs to refer to program elements such as variable or function names, databases, data types, environment variables, statements, and keywords.

Constant width bold

Shows commands or other text that should be typed literally by the user and for emphasis within code listings.

Constant width italic

Shows text that should be replaced with user-supplied values or by values determined by context.


This icon signifies a tip, suggestion, or general note.


This icon indicates a warning or caution.

Using Code Examples

This book is here to help you get your job done. In general, you may use the code in this book in your programs and documentation. You do not need to contact us for permission unless you’re reproducing a significant portion of the code. For example, writing a program that uses several chunks of code from this book does not require permission. Selling or distributing a CD-ROM of examples from O’Reilly books does require permission. Answering a question by citing this book and quoting example code does not require permission. Incorporating a significant amount of example code from this book into your product’s documentation does require permission.

We appreciate, but do not require, attribution. An attribution usually includes the title, author, publisher, and ISBN. For example: “Building iPhone Apps with HTML, CSS, and JavaScript by Jonathan Stark. Copyright 2010 Jonathan Stark, 978-0-596-80578-4.”

If you feel your use of code examples falls outside fair use or the permission given above, feel free to contact us at .

Safari® Books Online


Safari Books Online is an on-demand digital library that lets you easily search over 7,500 technology and creative reference books and videos to find the answers you need quickly.

With a subscription, you can read any page and watch any video from our library online. Read books on your cell phone and mobile devices. Access new titles before they are available for print, and get exclusive access to manuscripts in development and post feedback for the authors. Copy and paste code samples, organize your favorites, download chapters, bookmark key sections, create notes, print out pages, and benefit from tons of other time-saving features.

O’Reilly Media has uploaded this book to the Safari Books Online service. To have full digital access to this book and others on similar topics from O’Reilly and other publishers, sign up for free at

How to Contact Us

Please address comments and questions concerning this book to the publisher:

O’Reilly Media, Inc.
1005 Gravenstein Highway North
Sebastopol, CA 95472
800-998-9938 (in the United States or Canada)
707-829-0515 (international or local)
707-829-0104 (fax)

We have a web page for this book, where we list errata, examples, and any additional information. You can access this page at:

To comment or ask technical questions about this book, send email to:

For more information about our books, conferences, Resource Centers, and the O’Reilly Network, see our website at:


Writing a book is a team effort. My heartfelt thanks go out to the following people for their generous contributions.

Tim O’Reilly, Brian Jepson, and the rest of the gang at ORM for making the experience of writing this book so rewarding and educational.

Jack Templin, Providence Geeks, and RI Nexus for introducing me to the thriving tech scene in my own hometown. This book wouldn’t exist if it weren’t for Providence Geeks.

David Kandeda for his wonderfully obsessive pursuit of beauty. Whether it’s a bit of code, or a user interface animation, he can’t sleep until it’s perfect, and I love that.

Brian LeRoux, Brock Whitten, Rob Ellis, and the rest of the gang at Nitobi for creating and continuing to support PhoneGap.

Brian Fling for broadening my view of mobile beyond just the latest and greatest hardware. Brian knows mobile from back in the day; he’s a wonderful writer, and on top of that, a very generous guy.

PPK, John Gruber, John Allsopp, and John Resig for their contributions to and support of the underlying technologies that made this book possible.

Garrett Murray, Brian LeRoux, and the swarm of folks who generously posted comments and questions on the OFPS site for this book. Your feedback was very helpful and much appreciated.

Kazu, Chuckie, Janice, Chris, and the rest of the gang at Haruki for being so accommodating while I endlessly typed away at the high top by the door.

My wonderful family, friends, and clients for being understanding and supportive while I was chained to the keyboard.

And finally, Erica. You make everything possible. I love you!

Site last updated on: November 17, 2010 at 10:11:32 AM PST