A comprehensive introduction to creating Apps
for iPhone, iPad and iPod touch
Beginning
iPhone 4 Development
Exploring the iOS SDK
Dave Mark
|
Jack Nutting
|
Jeff LaMarche
Covers
iPad
and
iPod touch
1
Chapter
Welcome to the Jungle
So, you want to write iPhone, iPod touch, and iPad applications? Well, we can’t say that
we blame you. iOS, the core software of all of these devices, might just be the most
interesting new platform to come around in a long time. Certainly, it is the most
interesting mobile platform to date, especially now that Apple has provided a set of
elegant, well-documented tools for developing iOS applications. And with the release of
version 4 of the iOS software development kit (SDK), things have only gotten better.
What This Book Is
This book is a guide to help you get started down the path to creating your own iOS
applications. Our goal is to get you past the initial learning curve to help you understand
the way iOS applications work and how they are built. As you work your way through
this book, you will create a number of small applications, each designed to highlight
specific iOS features and show you how to control or interact with those features. If you
combine the foundation you’ll gain by making your way through this book with your own
creativity and determination, and then add in the extensive and well-written
documentation provided by Apple, you’ll have everything you need to build your own
professional iPhone and iPad applications.
TIP: Dave, Jack, and Jeff have a forum set up for this book. It’s a great place to meet like-
minded folks, get your questions answered, and even answer other people’s questions. It’s at
http://iphonedevbook.com/forum. Be sure to check it out!
What You Need
Before you can begin writing software for iOS, you’ll need a few things. For starters,
you’ll need an Intel-based Macintosh running Snow Leopard (OS X 10.6.5 or later). Any
recent Intel-based Macintosh computer—laptop or desktop—should work just fine.
1
CHAPTER 1: Welcome to the Jungle
2
You’ll also need to sign up to become a registered iOS developer. Apple requires this
step before you’re allowed to download the iOS SDK.
To sign up, navigate to
http://developer.apple.com/ios/, which will bring you to a
page similar to the one shown in Figure 1–1.
Figure 1–1. Apple’s iOS Dev Center web site
CHAPTER 1: Welcome to the Jungle
3
First, click the button labeled Log in. You’ll be prompted for your Apple ID. If you don’t
have an Apple ID, click the Create Apple ID button, create one, and then log in. Once
you are logged in, you’ll be taken to the main iOS development page. Not only will you
see a link to the SDK download, but you’ll also find links to a wealth of documentation,
videos, sample code, and the like—all dedicated to teaching you the finer points of iOS
application development.
One of the most important downloads on this page is Xcode, Apple’s integrated
development environment (IDE). Xcode includes tools for creating and debugging source
code, compiling applications, and performance tuning the applications you’ve written.
By the time you are finished with this book, you will become an Xcode aficionado!
SDK VERSIONS AND SOURCE CODE FOR THE EXAMPLES
As the versions of the SDK and Xcode evolve, the mechanism for downloading them will also change.
Sometimes the SDK and Xcode are featured as separate downloads; other times, they will be merged as a
single download. Bottom line: you want to download the latest released (nonbeta) version of the SDK and
Xcode.
This book has been written to work with the latest version of the SDK. In some places, we have chosen to
use new functions or methods introduced with version 4 that may prove incompatible with earlier versions
of the SDK. We’ll be sure to point those situations out as they arise in this book.
Be sure to download the latest and greatest source code archives from the book’s web site at
http://iphonedevbook.com.
We’ll update the code as new versions of the SDK are released, so be sure to check the site periodically.
Developer Options
The free SDK download option includes a simulator that will allow you to build and run
iPhone and iPad apps on your Mac. This is perfect for learning how to program for iOS.
However, the simulator does not support hardware-dependent features, such as the
iPhone’s accelerometer or camera. Also, the free option will not allow you to download
your applications onto your actual iPhone or other device. And it does not give you the
ability to distribute your applications on Apple’s App Store. For those capabilities, you’ll
need to sign up for one of the other options, which aren’t free:
The Standard program costs $99/year. It provides a host of
development tools and resources, technical support, distribution of
your application via Apple’s App Store, and, most important, the ability
to test and debug your code on an iOS device, rather than just in the
simulator.
The Enterprise program costs $299/year. It is designed for companies
developing proprietary, in-house iOS applications and for those
developing applications for the Apple’s App Store, and with more than
one developer working on the project.
CHAPTER 1: Welcome to the Jungle
4
For more details on these programs, visit http://developer.apple.com/programs/ios
and
http://developer.apple.com/programs/ios/enterprise to compare the two.
Because iOS supports an always-connected mobile device that uses other companies’
wireless infrastructure, Apple has needed to place far more restrictions on iOS
developers than it ever has on Mac developers (who are able—at least as of this
writing—to write and distribute programs with absolutely no oversight or approval from
Apple). Even though the iPod touch and the Wi-Fi–only versions of the iPad don’t use
anyone else’s infrastructure, they’re still subject to these same restrictions.
Apple has not added restrictions to be mean, but rather as an attempt to minimize the
chances of malicious or poorly written programs being distributed that could degrade
performance on the shared network. Developing for iOS may seem like it presents a lot
of hoops to jump through, but Apple has expended quite an effort to make the process
as painless as possible. And also consider that $99 is still considerably less than buying,
for example, Visual Studio, which is Microsoft’s software development IDE.
This may seem obvious, but you’ll also need an iPhone, iPod touch, or iPad. While much
of your code can be tested using the iOS simulator, not all programs can be. And even
those that can run on the simulator really need to be thoroughly tested on an actual
device before you ever consider releasing your application to the public.
NOTE: If you are going to sign up for the Standard or Enterprise program, you should go do it
right now. The approval process can take a while, and you’ll need that approval to be able to run
your applications on an actual device. Don’t worry, though, because all the projects in the first
several chapters and the majority of the applications in this book will run just fine on the iOS
simulator.
What You Need to Know
This book assumes that you already have some programming knowledge. It assumes
that you understand the fundamentals of object-oriented programming (you know what
objects, loops, and variables are, for example). It also assumes you are familiar with the
Objective-C programming language. Cocoa Touch, the part of the SDK that you will be
using through most of this book, uses Objective-C 2.0. But don’t worry if you’re not
familiar with the more recent additions to the Objective-C language. We highlight any of
the 2.0 language features we take advantage of, and explain how they work and why we
are using them.
You should also be familiar with iOS itself, as a user. Just as you would with any
platform for which you wanted to write an application, get to know the iPhone, iPad, or
iPod touch’s nuances and quirks. Take the time to get familiar with the iOS interface and
with the way Apple’s iPhone and/or iPad applications look and feel.