Enterprise developers everywhere cheered when Apple announced its official SDK in March 2008. The long-awaited development environment finally allowed developers to design commercial applications for the iPhone, and provided a distribution channel capable of reaching every single iPhone user. This book covers the officially sanctioned Apple SDK and subsequent APIs used to develop applications specifically tailored to the AppStore.

The Apple SDK represented great progress in mobile software development, and provided a fantastic open door for the quintessential "overnight millionaire" to walk through. As an SDK developer, you have a direct channel to millions of end users who have the opportunity to instantly purchase your product. The long-awaited removal of Apple's NDA further helped to culminate a significant enthusiasm for this fantastic device and business model. There is no doubt a great opportunity for innovation and profit with the iPhone SDK.

This enthusiasm must be tempered with realistic expectations, however. As an iPhone developer, you'll be designing on a platform that is still considered by and large a closed device. Your applications will run in a restrictive sandbox to prevent certain types of access, and Apple has restricted you from using many private APIs that can access more powerful resources on the device. You'll need to be aware of your environment's limitations so you don't burn hours on code with incorrect assumptions about what you can do.

While many see a pair of fuzzy handcuffs restraining the SDK, it is clearly a powerful enough platform to write good quality games and applications. The SDK introduces easy-to-use objects that are overlaid on the iPhone's more complex low-level frameworks. This makes coding things like user interfaces, global positioning queries, and even settings bundles a much less time-consuming task than with other development environments. Because of this, developers can focus on the more important aspects of a project. With just a few lines, you can create many different types of user interfaces, work with 3D animations, and mix audio sound. This book introduces you to the iPhone development paradigm and walks you through the frameworks that are key to designing full-featured software on the iPhone.

P2.1. Audience for This Book

This book is geared toward novice and experienced developers writing applications for the iPhone. You'll need some prior knowledge of coding to find this book useful. The iPhone development environment uses Objective-C, which you'll be introduced to immediately. The good news is that you can also use C and C++ in your applications, so anyone with preexisting knowledge should be able to pick up Objective-C pretty quickly. This book isn't a full introduction to Objective-C, but it will help you get your feet wet with a mini primer and countless complete code examples.

As you read this, consider that there is another side to the device that is not covered in this book. Many low-level objects and frameworks are off-limits to the SDK, but have been taken advantage of by the iPhone hacking community. You won't find any of these unsanctioned APIs in this book, with the exception of a few clearly marked examples, so as not to confuse you about what you can and can't use. If you're using the SDK to write applications that you will use internally, or if you'd like to get a better understanding of how the iPhone's plumbing works on a lower level, you may wish to complement this book with a copy of iPhone Open Application Development, Second Edition (O'Reilly). The two books combined will not only give you an understanding of what you can do, but also what you can't, as well as the kinds of functionality that you will inevitably compete with in the applications written by the hacking community.

P2.2. Organization of the Material

Chapter 1, explains how to get up and running with the iPhone SDK, and how to build and install sample applications.

Chapter 2, introduces you to the Interface Builder, a WYSIWYG tool used to design proprietary iPhone user interfaces.

Chapter 3, introduces you to the UI Kit framework and teaches you how to design basic user interface elements.

Chapter 4, explains event handling and basic geometric structures.

Chapter 5, shows you how to create and manage layers and transformations using Core Graphics and Quartz Core.

Chapter 6, shows you how to mix and play sound files using AVFoundation and how to record and play back digital sound streams using the Audio Toolbox framework.

Chapter 7, illustrates network programming with the CFNetwork framework.

Chapter 8, introduces you to the Core Location framework and shows you how to interact with the iPhone's GPS.

Chapter 9, explains the Address Book APIs and how to query and display contacts.

Chapter 10, covers the more advanced classes of UI Kit.

Chapter 11, explains how to read and write application preferences and work with property lists.

Chapter 12, explains how to construct a Cover Flow style album flipper.

Chapter 13, illustrates page flicking and how to flip between multiple views like pages in a book.

Chapter 14, explains how to add movie players to your application.

P2.3. Conventions Used in This Book

The following typographical conventions are used in this book:

Plain text

Used for menu titles, menu options, menu buttons, and keyboard accelerators.


Indicates new terms, URLs, filenames, Unix utilities, and command-line options.

Constant width

Indicates the contents of files, the output from commands, variables, types, classes, namespaces, methods, values, objects, and generally anything found in programs.

Constant width

Shows commands or other text that should be typed literally by the user, and parts of code or files highlighted to stand out for discussion.

Constant width italic

Shows text that should be replaced with user-supplied values.



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

This icon indicates a warning or caution.

P2.4. 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: "iPhone SDK Application Development by Jonathan Zdziarski. Copyright 2009 Jonathan Zdziarski, 978-0-596-15405-9."

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

The code examples in this book have been written and verified with Apple's iPhone SDK versions 2.1 and 2.2. As newer versions are released by Apple, minor changes to APIs could possibly be introduced. Be sure to consult any release notes included with newer versions of Apple's SDK, and consult Apple's iPhone OS Programming Guide for any new developments.

P2.5. Legal Disclaimer

The technologies discussed in this publication, the limitations on these technologies that the technology and content owners seek to impose, and the laws actually limiting the use of these technologies are constantly changing. Thus, some of the projects and instructions described in this publication may not work, may cause unintended harm to equipment or systems on which they are used, or may be inconsistent with applicable law or user agreements. Your use of these projects is at your own risk, and O'Reilly Media, Inc. disclaims responsibility for any damage or expense resulting from their use. In any event, you should take care that your use of these projects does not violate any applicable laws, including copyright laws.

P2.6. Safari® Books Online


When you see a Safari® Books Online icon on the cover of your favorite technology book, that means the book is available online through the O'Reilly Network Safari Bookshelf.

Safari offers a solution that's better than e-books. It's a virtual library that lets you easily search thousands of top tech books, cut and paste code samples, download chapters, and find quick answers when you need the most accurate, current information. Try it for free at

P2.7. We'd Like to Hear from You

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:

P2.8. Acknowledgments

Special thanks to Layton Duncan, Brian Whitman, and others who have shared their nifty discoveries with me. Thanks also to Jonathan Hohle, Dallas Brown, Brad O'Hearne, and John Draper for their technical reviews of this book and suggestions to help make it even better. Finally, thanks to my wife for not murdering me in my sleep as I obsessed about this book.