About this Book

iPhone and iPad in Action is an introductory book, intended to teach the basics of iPhone SDK programming in a tutorial form. It’s an updated revision of iPhone in Action, which first appeared in 2008. We encourage you to read it straight through, from chapter 1 to 19. This will introduce the platform, how to program for the iPhone and iPad, and step you through the entire process in turn.

The audience

We’ve done our best to make this book accessible to everyone who is interested in writing native programs for the iPhone and iPad. We think it will be especially useful to people who are looking to dive into the iPhone/iPad arena, because it will allow you to create native applications for all of Apple’s iDevices.

If you want to learn about iPhone SDK programming, you should have some experience with programming in general. It’d be best if you’ve worked with C before, but that’s not a necessity; if you haven’t, you can read our introduction to Objective-C in chapter 2, and you should probably expect to do some research on your own to clarify things. There’s no need to be familiar with Objective-C, Cocoa, or Apple programming in general. We’ll give you everything you need to become familiar with Apple’s unique programming style. You’ll probably have a leg up if you understand object-oriented concepts; but it’s not necessary (and again, you’ll find an introduction in chapter 2).

Roadmap

Chapter 1 explains the details of the iPhone and iPad and how they differ from the mobile phones that predated the iPhone. It also contains one of this book’s most important concepts: the unique features that make the iPhone and iPad stand out from the pack and which are also of importance to programmers.

Chapter 2 kicks things off by highlighting Objective-C, which is the programming language used on the iPhone SDK, and the iPhone OS, which is an immense collection of frameworks that makes many complex tasks easy.

Chapter 3 looks at Xcode, the first major tool in the SDK. This integrated development environment does more than just compile your code. It also helps you correct simple errors as you type and provides quick, integrated access to all the iPhone programming documents.

Chapter 4 shifts the focus to Interface Builder, a graphical design environment that allows you to create and place interface objects without writing a single line of code. Interface Builder is a powerful time-saver for programmers and is used throughout the rest of the text.

Chapter 5 covers simple view controllers. The basic view controller is an important building block of the MVC paradigm, dividing control from view; and the table view controller provides an easy way to organize information while matching the standard iPhone OS look and feel.

Chapter 6 steps back to talk about user interaction. It covers events, which users generate by touching the screen with one or more fingers, and actions, which happen when users interact with a control object like a button or a slider.

Chapter 7 finishes our look at view controllers by examining two more advanced possibilities. The tab bar view controller allows for modal selection between multiple pages of content, and the navigation view controller adds hierarchy to tables.

Chapter 8 opens the SDK toolkit by talking about data. This includes user input, such as actions and preferences; data storage, such as files; and tools that combine input and storage, such as the devices’ address book.

Chapter 9 goes into more advanced data strategies. In this chapter, you learn how to store complex data in an SQLite database or by using Core Data.

Chapter 10 highlights two of the most unique features on the iPhone and iPad—the accelerometer and the GPS—showing how the iPhone can track movement through space.

Chapter 11 covers another of the device’s strengths—media—by showing how to do basic work with pictures, movies, and sounds

Chapter 12 looks at working with audio. It discusses how to play and record audio using a device’s microphone and speakers.

Chapter 13 provides an extensive look at graphics, centering on the iPhone’s and iPad’s vector graphic language, Quartz 2D. It also offers a brief overview of Core Animation and touches on OpenGL for the iPhone OS.

Chapter 14 examines how you can use the iPhone and iPad to interact with the internet. This chapter moves through the entire hierarchy of internet communication, from low-level host connections to URLs, from web views to modern social languages like XML and JSON.

Chapter 15 takes you through the entire process of creating a multiplayer pong game on the iPhone or iPad. You learn everything about peer-to-peer communication using the Game Kit framework.

Chapter 16 shows you how to handle push notifications in your applications. It also provides a simple example of how to create your own push notification server using PHP.

Chapter 17 takes an in-depth look at the Map Kit framework. It shows you everything you need in order to integrate fully functional Google maps in any application.

Chapter 18 walks you through one of the main methods for creating a virtual store in your applications. Using the Store Kit framework, you learn every step of the process, from creating products to processing purchases.

Chapter 19 ties up some loose ends and gives you a look at some of the new libraries added to the iPhone SDK. It also provides you with a roadmap for the iPhone 4.0 SDK and points you in a direction to get more information.

The appendixes contain some additional information that didn’t fit with the flow of the main text. Appendix A contains a list of SDK objects and what they do. Appendix B features links for many websites of note for iPhone SDK programming. Appendix C includes the current information on how to deploy your SDK programs to actual devices. Appendix D shows many techniques that you can use to convert iPhone applications into iPad applications.

Code conventions and downloads

Code examples appear throughout this book. Longer listings appear under clear listing headings, and shorter listings appear between lines of text. All code is set in a special font like this to differentiate it from the regular font. Class names have also been set in code font; if you want to type it into your computer, you’ll be able to clearly make it out.

With the exception of a few cases of abstract code examples, all code snippets began life as working programs. You can find the complete set of programs at http://www.manning.com/iPhoneandiPadinAction. You’ll find two ZIP files there, one each for the SDK programs. We encourage you to try the programs as you read; they often include additional code that doesn’t appear in the book and provides more context. In addition, we feel that seeing a program working can greatly elucidate the code required to create it.

The code snippets in this book all include extensive explanations. We often include short annotations beside the code; and sometimes numbered cueballs beside lines of code link the subsequent discussion to the code lines.

Software requirements

An Intel-based Macintosh running OS X 10.6 or higher is absolutely required to do SDK development. You also need to have the iPhone SDK, but this is freely downloadable as soon as you sign up with Apple. The book offers full coverage of the iPhone SDK 3.2, with some discussion of iOS SDK 4.0.

Author Online

This book is intended to be an introduction to iPhone programming. Although it covers an extensive amount of information about the iPhone and iPad, there’s a lot that couldn’t be covered in a single book. Feel free to come chat with the authors online about additional topics.

The purchase of iPhone and iPad in Action includes free access to a private web forum run by Manning Publications, where you can post comments about the book, ask technical questions, and receive help from the authors and from other users. To access the forum and subscribe to it, point your web browser to http://www.manning.com/iPhoneandiPadinAction. The Author Online forum and the archives of previous discussions will be accessible from the publisher’s website for as long as the book is in print.

Brandon frequently posts tutorials and code snippets on his iPhone development blog at http://icodeblog.com. He is also very active on Twitter and available to answer most of your iPhone and iPad development questions. Find him on Twitter at http://twitter.com/brandontreb.

Christopher and Shannon’s main hangout is http://iphoneinaction.manning.com. This blog contains the newest noteworthy links they have found, discussions about “missing classes” that we didn’t cover in this book, and occasional articles of more weight.

And we continue to host Christopher’s original iPhone forum on web development, which you can find at http://www.iphonewebdev.com.

About the title

By combining introductions, overviews, and how-to examples, the In Action books are designed to help learning and remembering. According to research in cognitive science, the things people remember are things they discover during self-motivated exploration.

Although no one at Manning is a cognitive scientist, we are convinced that for learning to become permanent it must pass through stages of exploration, play, and, interestingly, retelling of what is being learned. People understand and remember new things, which is to say they master them, only after actively exploring them. Humans learn in action. An essential part of an In Action guide is that it’s example-driven. It encourages the reader to try things out, to play with new code, and explore new ideas.

There is another, more mundane, reason for the title of this book: our readers are busy. They use books to do a job or to solve a problem. They need books that allow them to jump in and jump out easily and learn just what they want just when they want it. They need books that aid them in action. The books in this series are designed for such readers.

About the cover illustration

The illustration on the cover of iPhone and iPad in Action is captioned “Habit of a Lady of Indostan.” It shows a woman in an intricately decorated dress holding a long-stemmed flower. The image is taken from the four-volume Collection of the Dress of Different Nations by Thomas Jefferys (1757–1752). This comprehensive work, with its beautiful and detailed drawings, has influenced European theatrical costume design for over 200 years. We chose this figure because of its graceful posture and elaborate dress.

Indostan, or as it used to be called, the “Indostanic Peninsula,” is the former name of South Asia, which is comprised of India, Pakistan, Bangladesh, Sri Lanka, the Maldives, and the Himalayan states of Bhutan and Nepal. Their collective historical background may be referred to as “the Indian Civilization,” which sets these countries apart from the rest of the Asian continent. Indostan was also called Hindustan, and over time it came to mean the Indian subcontinent.

Today, women in India and neighboring countries can still be seen wearing the traditional sari, which is made of a single long strip of unstitched silk cloth, embroidered with gold or silver thread. The woman on the cover is wearing a fitted dress that has sleeves and a defined waist and was likely worn for special occasions, such as weddings or formal receptions.

Dress codes have changed in the last two hundred and fifty years, and the diversity by country and by region, so rich at the time, has faded away. It’s now hard to tell apart the inhabitants of different continents, let alone different regions. Perhaps we have traded cultural diversity for a more varied personal life—certainly a more varied and faster-paced technological life.

At a time when it’s hard to tell one computer book from another, Manning celebrates the inventiveness and initiative of the computer business with book covers based on the rich diversity of regional life of more than two centuries ago, brought back to life by old illustrations such as this one.

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

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