Preface

So, you want to write applications for the iPhone. The first thing you should know is that the iPhone is by and large a closed device, and Apple has taken steps to lock users out of the operating system. This hasn’t stopped people. In October 2007, Apple announced in an earnings statement that over 250,000 units had been sold with the intent of unlocking them for use on other networks. Within the first month of v1.1’s software release, Nicholas Penree’s jailbreakme.com site logged over one million units that were freed to run third-party applications. Sites hosting iPhone cracking tools have reported record traffic, and even Apple’s own employees traipse around the Genius Bar touting their hacked devices. Well-respected hackers joined the effort to crack the iPhone, and once in, realized it’s just as elegant on the inside—a well-planned mobile platform well worth developing applications on. Within a few months, a free, open source (http://open-source.org) compiler for building iPhone applications was released—not by Apple, but by the open source community. Today, full-featured iPhone applications are ubiquitous. And all of this was accomplished on a device that was intended to be closed.

Apple finally woke up to the fact that developers were not satisfied with Safari-based applications. In late 2007, they announced an SDK for the iPhone to be released the first quarter of 2008, but as of the time of this writing, we don’t know what the availability will be, or what restrictions will be placed on it. What we do have today, however, is almost as good and in some ways better. The free SDK, affectionately called “the tool chain,” isn’t tied down with licensing, nor is it exclusive to running only on Apple’s operating system. In fact, a Linux user (and soon Windows users) can build and install applications on their iPhone without ever touching a Mac.

The interfaces used by the free tool chain are in every way identical to what Apple must release with their own SDK. The frameworks available on the iPhone employ a standard set of interfaces used by Apple’s preloaded iPhone applications. All major tasks are performed by these frameworks, including the entire user interface, playing sounds and music, working with graphics and animation, and even displaying web pages. Within the first few months of the iPhone’s high-profile life in the public market, the iPhone hacking community extracted these interfaces and built their own software development kit.

So this book, which was written based on the free tool chain, uses the same code that Apple’s XCode or any other compiler would need to use to compile iPhone applications. Should Apple follow through with the release of a native SDK, the classes, methods, and examples presented in this book are very likely to work with both SDKs. In fact, Apple would have to rewrite every framework—and every single application on the iPhone—to make this book obsolete.

With tool chain in hand, and many sleepless nights of tomhackery, the community has been able to learn how to use the frameworks and interfaces available to design spectacular third-party applications. This book walks through the frameworks that are key to designing this full-featured software on the iPhone, with pointers to tools that are available to take advantage of the other frameworks not documented here.

The iPhone is a superb device, and in spite of the politics surrounding its availability to developers, the community is growing fast. With or without Apple’s help, the iPhone is likely to give birth to many commercial markets for itself, and possibly grow beyond the success of its predecessors, the PocketPCs and the Symbians that formerly owned the mobile market space.

As you read this book, you probably won’t realize just how good you’ve got it. The simplicity you’ll see in this book reflects thousands of hours of work by the active development community chipping away at the nearly impossible challenges that were involved in this task. The old school methods for getting anything done on the iPhone were laborious if not exhausting, and could have filled up volumes of books alone. Even after we figured out how to jailbreak the very first iPhone, we couldn’t do anything with it until we came up with a grand scheme to fool it into running SSH. It took another month beyond that before the first GUI application was even written.

Work continues today to figure out many of the proprietary interfaces on the iPhone, and we welcome anyone into the community with the know-how and perseverance to join us in this endeavor.

Audience for This Book

You’ll need some prior knowledge of coding to find this book useful. The iPhone framework uses Objective-C, which we’ll introduce you to in Chapter 2. 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 it up pretty quickly. If you don’t understand C or C++, there are many books available on the subject. This book isn’t a primer for any of these languages, but rather is designed to explain the proprietary classes and methods needed to write iPhone-specific applications.

Organization of the Material

Chapter 1, explains how to break into your iPhone.

Chapter 2, illustrates the makeup of an iPhone application and how to get the tool chain running on your desktop.

Chapter 3, introduces you to UIKit, which is at the core of developing iPhone applications and user interfaces.

Chapter 4, covers basic geometric concepts as used in the Core Graphics framework and event notifications.

Chapter 5, goes deeper into iPhone development by exploring raw video surfaces and 3-D transformations.

Chapter 6, covers the many different ways to record and play sounds and output a digital audio stream.

Chapter 7, illustrates many of the advanced user interface components of UIKit.

The Appendix highlights many miscellaneous hacks and open source classes to do cool things in your iPhone application.

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.

Italic

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 bold

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.

Tip

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

Warning

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: "iPhone Open Application Development by Jonathan Zdziarski. Copyright 2008 Jonathan Zdziarski, 978-0-596-51855-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

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 http://safari.oreilly.com.

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 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.

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:

http://www.oreilly.com/catalog/9780596518554/

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 web site at:

http://www.oreilly.com

Acknowledgments

Special thanks to Patrick Walton, Brian Whitman, John Bafford, Nicholas Penree, Elliot Kroo, Dino Pastos, Nate True, Steve Dunham, Nicolas Bacca, Daniel Peebles, Alexander Pick, Piergiorgio Zambrini, Aaron Alexander, Richard Thally, Justin Lazarow, Chris Zimman, Eric McDonald, and many others wishing to remain anonymous in the iPhone development community who have contributed sleepless nights, great humor, and cash from their own pockets to open the iPhone and build a solid foundation for application development.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.119.162.204