Table of Contents

Cover

Title Page

Copyright

Dedication

Credits

About the Author

Acknowledgments

Introduction

Who This Book Is For

What This Book Covers

How This Book Is Structured

What You Need to Use This Book

Conventions

Source Code and Answers Appendix

Errata

p2p.wrox.com

Part I: Getting Started

Chapter 1: Getting Started with iOS 4 Programming

Obtaining the iPhone SDK

Components of the iPhone SDK

Architecture of the iPhone OS

Some Useful Information before You Get Started

Summary

What You Learned In This Chapter

Chapter 2: Write Your First Hello World! Application

Getting Started with Xcode

Customizing Your Application Icon

Displaying a Splash Screen

Summary

What You Learned In This Chapter

Chapter 3: Views, Outlets, and Actions

Outlets and Actions

Using Views

Adding Views Dynamically Using Code

Understanding View Hierarchy

Summary

What You Learned In This Chapter

Chapter 4: View Controllers

The View-Based Application Template

The Window-Based Application Template

The Split View-Based Application Template

The Tab Bar Application Template

Summary

What You Learned In This Chapter

Chapter 5: Multi-Platform Support for the iPhone and iPad

Technique 1 — Modifying the Device Target Setting

Technique 2 — Creating Universal Applications

Technique 3 — Maintaining Two Code Bases

Making Your Choice

Summary

What You Learned In This Chapter

Chapter 6: Keyboard Inputs

Using the Keyboard

Customizing the Type of Inputs

Detecting the Presence of the Keyboard

Summary

What You Learned In This Chapter

Chapter 7: Screen Rotations

Responding to Device Rotations

Programmatically Rotating the Screen

Summary

What You Learned In This Chapter

Part II: Displaying and Persisting Data

Chapter 8: Using the Table View

A Simple Table View

Using the Table View in a Navigation-Based Application

Displaying Sections

Summary

What You Learned In This Chapter

Chapter 9: Application Preferences

Creating Application Preferences

Programmatically Accessing the Settings Values

Summary

What You Learned In This Chapter

Chapter 10: File Handling

Understanding the Application Folders

Using Property Lists

Copying Bundled Resources

Summary

What You Learned In This Chapter

Chapter 11: Database Storage Using SQLite3

Using SQLite3

Creating and Opening a Database

Bundling SQLite Databases with Your Application

Summary

What You Learned In This Chapter

Part III: Advanced iOS 4 Programming Techniques

Chapter 12: Simple Animations and Video Playback

Using the NSTimer Class

Transforming Views

Animating a Series of Images

Playing Video on the iPhone

Summary

What You Learned In This Chapter

Chapter 13: Accessing Built-In Applications

Sending E-Mails

Accessing the Camera and the Photo Library

Summary

What You Learned In This Chapter

Chapter 14: Recognizing Gestures

Recognizing Gestures

Detecting Touches

Summary

What You Learned In This Chapter

Chapter 15: Accessing the Accelerometer

Using the Accelerometer

Visualizing the Accelerometer Data

Using the Shake API to Detect Shakes

Summary

What You Learned In This Chapter

Part IV: Network Programming Techniques

Chapter 16: Web Services

Basics of Consuming XML Web Services

Consuming a Web Service in Your iPhone Application

Parsing the XML Response

Summary

What You Learned In This Chapter

Chapter 17: Bluetooth Programming

Using the Game Kit Framework

Implementing Voice Chatting

Summary

What You Learned In This Chapter

Chapter 18: Bonjour Programming

Creating the Application

Publishing a Service

Browsing for Services

Summary

What You Learned In This Chapter

Chapter 19: Apple Push Notification Service

Generating a Certificate Request

Generating a Development Certificate

Creating an Application ID

Creating the iPhone Application

Creating the Push Notification Provider

Summary

What You Learned In This Chapter

Chapter 20: Displaying Maps

Displaying Maps and Monitoring Changes Using the Map Kit

Getting Location Data

Summary

What You Learned In This Chapter

Chapter 21: Background Applications

Understanding Background Execution on the iPhone

Local Notification

Summary

What You Learned In This Chapter

Part V: Appendices

Appendix A: Testing on an Actual Device

Signing Up for the iPhone Developer Program

Obtaining the UDID of Your Device

Logging in to the iPhone Provisioning Portal

Generating a Certificate

Registering Your Devices

Creating an Application ID

Creating a Provisioning Profile

Understanding Application ID and the Wildcard

Preparing for App Store Submission

Summary

Appendix B: Getting Around in Xcode

Launching Xcode

Debugging Your Applications

Appendix C: Getting Around in Interface Builder

.xib Window

Designing the View

Inspector Window

Library

Outlets and Actions

Appendix D: Crash Course in Objective-C

Directives

Classes

Memory Management

Protocols

Selectors

Categories

Appendix E: Answers to Exercises

Chapter 2 Exercise Solutions

Chapter 3 Exercise Solutions

Chapter 4 Exercise Solutions

Chapter 5 Exercise Solutions

Chapter 6 Exercise Solutions

Chapter 7 Exercise Solutions

Chapter 8 Exercise Solutions

Chapter 9 Exercise Solutions

Chapter 10 Exercise Solutions

Chapter 11 Exercise Solutions

Chapter 12 Exercise Solutions

Chapter 13 Exercise Solutions

Chapter 14 Exercise Solutions

Chapter 15 Exercise Solutions

Chapter 16 Exercise Solutions

Chapter 17 Exercise Solutions

Chapter 18 Exercise Solutions

Chapter 19 Exercise Solutions

Chapter 20 Exercise Solutions

Chapter 21 Exercise Solutions

Index

Beginning iOS 4 Application Development

Published by Wiley Publishing, Inc. 10475 Crosspoint Boulevard Indianapolis, IN 46256

www.wiley.com

Copyright © 2010 by Wiley Publishing, Inc., Indianapolis, Indiana

Published simultaneously in Canada

ISBN: 978-0-470-91802-9

ISBN: 978-0-470-94983-2 (ebk)

ISBN: 978-1-118-00480-7 (ebk)

ISBN: 978-1-118-00481-4 (ebk)

Manufactured in the United States of America

10 9 8 7 6 5 4 3 2 1

No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, scanning or otherwise, except as permitted under Sections 107 or 108 of the 1976 United States Copyright Act, without either the prior written permission of the Publisher, or authorization through payment of the appropriate per-copy fee to the Copyright Clearance Center, 222 Rosewood Drive, Danvers, MA 01923, (978) 750-8400, fax (978) 646-8600. Requests to the Publisher for permission should be addressed to the Permissions Department, John Wiley & Sons, Inc., 111 River Street, Hoboken, NJ 07030, (201) 748-6011, fax (201) 748-6008, or online at http://www.wiley.com/go/permissions.

Limit of Liability/Disclaimer of Warranty: The publisher and the author make no representations or warranties with respect to the accuracy or completeness of the contents of this work and specifically disclaim all warranties, including without limitation warranties of fitness for a particular purpose. No warranty may be created or extended by sales or promotional materials. The advice and strategies contained herein may not be suitable for every situation. This work is sold with the understanding that the publisher is not engaged in rendering legal, accounting, or other professional services. If professional assistance is required, the services of a competent professional person should be sought. Neither the publisher nor the author shall be liable for damages arising herefrom. The fact that an organization or Web site is referred to in this work as a citation and/or a potential source of further information does not mean that the author or the publisher endorses the information the organization or Web site may provide or recommendations it may make. Further, readers should be aware that Internet Web sites listed in this work may have changed or disappeared between when this work was written and when it is read.

For general information on our other products and services please contact our Customer Care Department within the United States at (877) 762-2974, outside the United States at (317) 572-3993 or fax (317) 572-4002.

Wiley also publishes its books in a variety of electronic formats. Some content that appears in print may not be available in electronic books.

Library of Congress Control Number: 2010932418

Trademarks: Wiley, the Wiley logo, Wrox, the Wrox logo, Wrox Programmer to Programmer, and related trade dress are trademarks or registered trademarks of John Wiley & Sons, Inc. and/or its affiliates, in the United States and other countries, and may not be used without written permission. All other trademarks are the property of their respective owners. Wiley Publishing, Inc. is not associated with any product or vendor mentioned in this book.

To my family:

Thanks for the understanding and support while I worked on getting this book ready! I love you all!

Credits

Acquisitions Editor

Scott Meyers

Senior Project Editor

Ami Frank Sullivan

Technical Editor

Trenton Shumay

Production Editor

Rebecca Anderson

Copy Editor

Luann Rouff

Editorial Director

Robyn B. Siesky

Editorial Manager

Mary Beth Wakefield

Associate Director of Marketing

David Mayhew

Production Manager

Tim Tate

Vice President and Executive Group Publisher

Richard Swadley

Vice President and Executive Publisher

Barry Pruett

Associate Publisher

Jim Minatel

Project Coordinator, Cover

Lynsey Stanford

Compositor

James D. Kramer, Happenstance Type-O-Rama

Proofreader

Nancy Carrasco

Indexer

Johnna VanHoose Dinse

Cover Designer

Michael E. Trent

Cover Image

© istockphoto.com/-M-I-S-H-A-

About the Author

Wei-Meng Lee is a technologist and founder of Developer Learning Solutions (www.learn2develop.net), a technology company specializing in hands-on training for the latest Microsoft and Mac OS X technologies. He is also an established author with Wrox and O’Reilly.

Wei-Meng first started the iPhone programming course in Singapore, and it has since received much positive feedback. His hands-on approach to iPhone/iPad programming makes understanding the subject much easier than reading books, tutorials, and documentation from Apple.

Contact Wei-Meng at weimenglee@learn2develop.net.

About the Technical Editor

Trent Shumay is the founder and Chief Architect at Finger Food Studios Inc. in the Vancouver, BC area. After graduating from the UBC Computer Science program, Trent spent thirteen years in the gaming and interactive entertainment space, where handheld gaming devices ignited his passion for mobile development. Today, Finger Food Studios focuses on developing media-rich, interactive mobile and Web applications. You can reach Trent directly at trent@fingerfoodstudios.com.

Acknowledgments

After much speculation and rumor, Apple has finally released the iPhone 4 amid fanfare and excitement. With the new iPhone 4 comes a new OS — iOS 4, which incorporates many enhancements, most notably the ability to support background applications. I was very fortunate to be able to work with the new OS while it was in its beta phase and even more excited to learn that I would be working on an iPhone 4 book! Writing a book is always exciting, but along with it come long hours of hard work, straining to get things done accurately and correctly. For this, I would like to take this opportunity to thank a number of people who made this book possible.

First, I want to thank my acquisitions editor Scott Meyers, who had faith in me when he signed me up for this book. Thanks for standing by me and always being there to help. I hope I have not disappointed you. Thank you, Scott!

Next, a huge thanks to Ami Sullivan, my editor, who is always a pleasure to work with. After working together on three books, we have built up a rapport and totally understand how each other works. With every new book that I work on with Ami, I learn new things. Thanks for the guidance, Ami!

I should not forget the heroes behind the scene: copy editor Luann Rouff and technical editor Trenton Shumay. They have been eagle-eye editing the book, making sure that every sentence makes sense — both grammatically as well as technically. Thanks, Luann and Trent!

Last, but not least, I want to thank my parents, and my wife, Sze Wa, for all the support they have given me. They have selflessly adjusted their schedules to accommodate my busy schedule when I was working on this book. My wife, as always, has stayed up with me on numerous nights as I was furiously working to meet the deadlines, and for this I would like to say to her and my parents: “I love you all!” Finally, to our lovely dog, Ookii, thanks for staying by our side. Now that the book is done, we can look forward to an earlier night.

Introduction

Within a short time span of six months, Apple revised the iPhone OS twice. The first time was in January 2010, when Apple announced a magical and revolutionary product: the iPad. Because the iPad is a tablet computer that is based on the iPhone OS, this meant that there were instantly more than 250,000 applications that could run on the iPad. Then, in April Apple announced (and subsequently shipped in June) the next major release of the iPhone OS — 4.0. Apple also took this opportunity to rename this new release of the OS, calling it iOS. This signifies Apple’s grand plan to run the iPhone OS on a wide variety of devices, not just on phones. Included with the new release of the OS is a new SDK, the iPhone SDK 4, which enables developers to take advantage of the various features provided by the operating system — key of which is the capability to run background applications.

When I first started learning about iPhone and iPad development, I went through the same journey that most developers go through: Write a Hello World application, play around with Interface Builder, try to understand what the code is doing, and repeat that process. I was also overwhelmed by the concept of a View Controller, and wondered why it was needed if I simply wanted to display a view. My background in developing for Windows Mobile and Android did not help much, and I had to start working with this concept from scratch.

This book was written to help jumpstart beginning iPhone and iPad developers. It covers the various topics in such a manner that you will progressively learn without being overwhelmed by the details. I adopt the philosophy that the best way to learn is by doing, hence the numerous hands-on “Try It Out” sections in each chapter, which first show you how to build something and then explain “How It Works.”

Although iPhone and iPad programming is a huge topic, my aim for this book is to get you started with the fundamentals, help you understand the underlying architecture of the SDK, and appreciate why things are done certain ways. It is beyond the scope of this book to cover everything under the sun related to iPhone and iPad programming, but I am confident that after reading this book (and doing the exercises), you will be well equipped to tackle your next iPhone or iPad programming challenge.

Who This Book Is For

This book is for the beginning iPhone and iPad developer who wants to start developing applications using the Apple iPhone SDK. To truly benefit from this book, you should have some background in programming and at least be familiar with object-oriented programming concepts. If you are totally new to the Objective-C language, you might want to jump straight to Appendix D, which provides an overview of the language. Alternatively, you can use Appendix D as a quick reference while you tackle the various chapters, checking out the syntax as you try the exercises. Depending on your learning style, one of those approaches should work best for you.

While most of the chapters are geared toward developing for the iPhone, the concepts apply to iPad development as well. In cases where specific features are available only on the iPad, they will be pointed out.

All the examples discussed in this book were written and tested using the iPhone SDK 4.0. Even though Apple continues to call it the iPhone SDK, it can be used to develop iPhone, iPod touch, and iPad applications. At the time of writing (July 2010), Apple continues to use the term “iPhone Simulator” to refer to the simulator that enables you to simulate both an iPhone and iPad. While every effort has been made to ensure that the screen shots are as current as possible, the actual screen that you see may differ when the iPhone SDK is revised.

What This Book Covers

This book covers the fundamentals of iPhone and iPad programming using the iPhone SDK. It is divided into 21 chapters and five appendices.

Chapter 1: Getting Started with iOS 4 Programming covers the various tools found in the iPhone SDK and explains their uses in iPhone and iPad development.

Chapter 2: Write Your First Hello World! Application gets you started with Xcode and Interface Builder to build a Hello World application. The focus is on giving you some hands-on practice getting a project up and running quickly. More details on the various project components are covered in subsequent chapters.

Chapter 3: Views, Outlets, and Actions covers the fundamental concepts of iPhone and iPad programming: outlets and actions. You learn how outlets and actions allow your code to interact with the visual elements in Interface Builder and why they are an integral part of every iPhone and iPad application. You will also learn about the various UI widgets known as views that make up the user interface of your application.

Chapter 4: View Controllers discusses the various View Controllers available in the iPhone SDK. You will learn how to develop different types of applications — View-based, Window-based, Split View–based, as well as Tab Bar applications.

Chapter 5: Multi-Platform Support for the iPhone and iPad shows how you can port your iPhone applications to the iPad platform. You will also learn how to create universal applications that will run on both the iPhone and the iPad.

Chapter 6: Keyboard Inputs shows you how to deal with the virtual keyboard in your iPhone or iPad. You learn how to hide the keyboard on demand and how to ensure that your views are not blocked by the keyboard when it is displayed.

Chapter 7: Screen Rotations demonstrates how you can reorient your application’s UI when the device is rotated. You learn about the various events that are fired when the device is rotated, and how to force your application to be displayed in a certain orientation.

Chapter 8: Using the Table View explores one of the most powerful views in the iPhone SDK — the Table view. The Table view is commonly used to display rows of data. In this chapter, you also learn how to implement search capabilities in your Table view.

Chapter 9: Application Preferences discusses the use of application settings to persist application preferences. Using application settings, you can access preferences related to your application through the Settings application available on the iPhone and iPad.

Chapter 10: File Handling shows how you can persist your application data by saving the data to files in your application’s sandbox directory. You also learn how to access the various folders available in your application sandbox.

Chapter 11: Database Storage Using SQLite3 covers the use of the embedded SQLite3 database library to store your data.

Chapter 12: Simple Animations and Video Playback provides an overview of the various techniques you can use to implement basic animations on the iPhone and iPad. You also learn about the various affine transformations supported by the iPhone SDK. In addition, you learn how to playback video on the iPhone and iPad.

Chapter 13: Accessing Built-In Applications describes the various ways you can access the iPhone and iPad’s built-in applications, such as the Photo Library, Contacts, and others. You also learn how you can invoke built-in applications such as Mail and Safari from within your applications.

Chapter 14: Recognizing Gestures provides an overview of the various gesture recognizers available in the iPhone SDK to help your device interpret user’s input gestures.

Chapter 15: Accessing the Accelerometer shows how you can access the accelerometer that is included with every iPhone and iPad. You will also learn how to detect shakes to your device.

Chapter 16: Web Services teaches you how to consume Web services from within your iPhone and iPad application. You will learn the various ways to communicate with Web services — SOAP, HTTP GET, and HTTP POST. You will also learn how to parse the XML result returned by the Web service.

Chapter 17: Bluetooth Programming explores the use of the Game Kit framework for Bluetooth programming. You will learn how to enable two devices to communicate using a Bluetooth connection, and how to implement voice chatting over a Bluetooth connection.

Chapter 18: Bonjour Programming shows how you can publish services on the network using the Bonjour protocol.

Chapter 19: Apple Push Notification Services explains how you can implement applications that use push notifications. The APNs allows your applications to continuously receive status updates from a service provider even though the application may not be running.

Chapter 20: Displaying Maps demonstrates how to build a location-based services application using the Map Kit framework. You will also learn how to obtain geographical location data and use it to display a map.

Chapter 21: Background Applications shows how to build applications that can continue to run in the background when the user switches to another application. You will also learn how to use the new local notifications feature to schedule notifications that will fire at specific time intervals.

Appendix A: Testing on an Actual Device outlines the steps you need to take to test your application on a real device.

Appendix B: Getting Around in Xcode provides a quick run-through of the many features in Xcode.

Appendix C: Getting Around in Interface Builder provides an overview of the many features of Interface Builder.

Appendix D: Crash Course in Objective-C offers a brief tutorial in Objective-C. Readers who are new to this language should read this chapter before getting started.

Appendix E: Answers to Exercises contains the solutions to the end-of-chapter exercises found in every chapter except Chapter 1. Please note, Appendix E is located online at Wrox.com.

How This Book Is Structured

This book breaks down the task of learning iPhone and iPad programming into several smaller chunks, enabling you to digest each foundational topic before delving into a more advanced topic. In addition, some chapters cover topics already discussed in a previous chapter. That’s because there is usually more than one way of doing things in Xcode and Interface Builder, so this approach enables you to learn the different techniques available for developing iPhone and iPad applications.

If you are a total beginner to iPhone programming, start with Chapters 1 and 2. After you are comfortable with the basics, head to the appendices to read more about the tools and language you are using. Once you are ready, you can continue with Chapter 3 and gradually move into more advanced topics.

A useful feature of this book is that all the code samples in each chapter are independent of those discussed in previous chapters. That gives you the flexibility to dive right into the topics that interest you and start working on the Try It Out projects.

What You Need to Use This Book

Most of the examples in this book run on the iPhone Simulator (which is included with the iPhone SDK). For exercises that access the hardware (such as the accelerometer), you need a real iPhone or iPad. In general, to get the most out of this book, having a real iPhone or iPad device is not necessary (although it is definitely required for testing if you plan to deploy your application on the App Store).

Conventions

To help you get the most from the text and keep track of what’s happening, we’ve used a number of conventions throughout the book.

TRY IT OUT: These Are Exercises or Examples for You to Follow

The Try It Out sections, which appear once or more per chapter, provide hands-on exercises to work through as you follow the text in the book.

1. They usually consist of a set of numbered steps.

2. Follow the steps with your copy of the project files.

How It Works

After each Try It Out section, these sections explain the code you’ve typed in detail.

As for other conventions in the text:

New terms and important words are highlighted in italics when first introduced.

Keyboard combinations are treated like this: Control-R.

Filenames, URLs, and code within the text are treated like so: persistence.properties.

Code is presented in two different ways:

We use a monofont type with no highlighting for most code examples.

We use bold to emphasize code that is of particular importance in the present context.

Boxes like this one hold important, not-to-be forgotten information that is directly relevant to the surrounding text.

Notes, tips, hints, tricks, and asides to the current discussion look like this.

COMMON MISTAKES This feature, Common Mistakes, helps you avoid the obstacles that many new practitioners find themselves negotiating.

Source Code and Answers Appendix

As you work through the examples in this book, you may choose either to type in all the code manually or to use the source code files that accompany the book. All the source code used in this book is available for download at www.wrox.com. When at the site, simply locate the book’s title (use the Search box or one of the title lists) and click the Download Code link on the book’s detail page to obtain all the source code for the book. Code that is included on the website is highlighted by the following icon and/or CodeNote, as shown following the icon:

Listings include the filename in the title. If it is just a code snippet, you’ll find the filename in a CodeNote such as this:

Code zip filename available for download at wrox.com

After you download the code, just decompress it with your favorite compression tool. Alternatively, go to the main Wrox code download page at www.wrox.com/dynamic/books/download.aspx to see the code available for this book and all other Wrox books.

Please note, Appendix E, Answers to Exercises, is available as a PDF for download.

Because many books have similar titles, you may find it easiest to search by ISBN; this book’s ISBN is 978-0-470-91802-9.

Errata

We make every effort to ensure that there are no errors in the text or the code. However, no one is perfect and mistakes do occur. If you find an error in one of our books, such as a spelling mistake or a faulty piece of code, we would be very grateful for your feedback. By sending in errata, you may save another reader hours of frustration and at the same time help us provide even higher-quality information.

To find the errata page for this book, go to www.wrox.com and locate the title using the Search box or one of the title lists. Then, on the book details page, click the Book Errata link. On this page, you can view all errata that has been submitted for this book and posted by Wrox editors. A complete book list, including links to each book’s errata, is also available at www.wrox.com/misc-pages/booklist.shtml.

If you don’t spot “your” error on the Book Errata page, go to www.wrox.com/contact/techsupport.shtml and complete the form there to send us the error you have found. We’ll check the information and, if appropriate, post a message to the book’s errata page and fix the problem in subsequent editions of the book.

p2p.wrox.com

For author and peer discussion, join the P2P forums at p2p.wrox.com. The forums are a Web-based system for you to post messages relating to Wrox books and related technologies and interact with other readers and technology users. The forums offer a subscription feature to e-mail you topics of interest of your choosing when new posts are made to the forums. Wrox authors, editors, other industry experts, and your fellow readers are present on these forums.

At http://p2p.wrox.com, you will find a number of different forums that will help you not only as you read this book, but also as you develop your own applications. To join the forums, just follow these steps:

1. Go to p2p.wrox.com and click the Register link.

2. Read the terms of use and click Agree.

3. Complete the required information to join as well as any optional information you want to provide and click Submit.

4. You will receive an e-mail with information describing how to verify your account and complete the joining process.

After you join, you can post new messages and respond to messages that other users post. You can read messages at any time on the Web. If you want to have new messages from a particular forum e-mailed to you, click the Subscribe to This Forum icon by the forum name in the forum listing.

For more information about how to use the Wrox P2P, be sure to read the P2P FAQs for answers to questions about how the forum software works as well as for many common questions specific to P2P and Wrox books. To read the FAQs, click the FAQ link on any P2P page.

Part I

Getting Started

Chapter 1: Getting Started with iOS 4 Programming

Chapter 2: Write Your First Hello World! Application

Chapter 3: Views, Outlets, and Actions

Chapter 4: View Controllers

Chapter 5: Multi-Platform Support for the iPhone and iPad

Chapter 6: Keyboard Inputs

Chapter 7: Screen Rotations

Chapter 1

Getting Started with iOS 4 Programming

What You Will Learn In This Chapter

How to obtain the iPhone SDK

Components included in the iPhone SDK

Features of the development tools — Xcode, Interface Builder, iPhone Simulator

Capabilities of the iPhone Simulator

Architecture of the iPhone OS

Characteristics of the iPhone

Welcome to the world of iPhone programming! That you are now holding this book shows that you are fascinated with the idea of developing your own iPhone (and iPad) applications and want to join the ranks of the tens of thousands of developers whose applications are already deployed in the App Store.

As the Chinese adage says, “To accomplish your mission, first sharpen your tools.” Successful programming requires that you first know your tools well. Indeed, this couldn’t be more true for iPhone programming — you need to know quite a few tools before you can even get started. Hence, this chapter describes the various relevant tools and information you need to jump on the iPhone development bandwagon.

Without further ado, it’s time to get down to work.

Obtaining the iPhone SDK

To develop for the iPhone, you first need to sign up as a registered iPhone developer at http://developer.apple.com/iphone/program/start/register/. Registration is free and provides you with access to the iPhone SDK (software development kit) and other resources that are useful for getting started.

At the time of writing, iOS (the iPhone OS) 4 is supported only on the iPhone and the iPod touch. The iPad still runs on the older iPhone OS 3.2 version. However, the iPhone SDK 4.0 supports both iPhone and iPad development.

Because the iPad also uses the iPhone OS, throughout this book you will often see the term “iPhone” used.

After signing up, you can download the iPhone SDK (version 4; see Figure 1-1).

Figure 1-1

Before you install the iPhone SDK, make sure you satisfy the following system requirements:

Only Intel Macs are supported, so if you have another processor type (such as the older G4 or G5 Macs), you’re out of luck.

Your system is updated with the latest Mac OS X release.

An actual iPhone/iPad is highly recommended, although not strictly necessary. To test your application, you can use the included iPhone Simulator (which enables you to simulate an iPhone or an iPad). However, to test certain hardware features like GPS, the accelerometer, and such, you need to use a real device.

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!