BN.com Gift Guide

The iPhone Developer's Cookbook: Building Applications with the iPhone SDK

Paperback (Print)
Used and New from Other Sellers
Used and New from Other Sellers
from $1.99
Usually ships in 1-2 business days
(Save 95%)
Other sellers (Paperback)
  • All (55) from $1.99   
  • Used (55) from $1.99   

Overview

“This book would be a bargain at ten times its price! If you are writing iPhone software, it will save you weeks of development time. Erica has included dozens of crisp and clear examples illustrating essential iPhone development techniques and many others that show special effects going way beyond Apple’s official documentation.”

—Tim Burks, iPhone Software Developer, TootSweet Software

“Erica Sadun’s technical expertise lives up to the Addison-Wesley name. The iPhone Developer’s Cookbook is a comprehensive walkthrough of iPhone development that will help anyone out, from beginners to more experienced developers. Code samples and screenshots help punctuate the numerous tips and tricks in this book.”

—Jacqui Cheng, Associate Editor, Ars Technica

“We make our living writing this stuff and yet I am humbled by Erica’s command of her subject matter and the way she presents the material: pleasantly informal, then very appropriately detailed technically. This is a going to be the Petzold book for iPhone developers.”

—Daniel Pasco, Lead Developer and CEO, Black Pixel Luminance

The iPhone Developer’s Cookbook: Building Applications with the iPhone SDK should be the first resource for the beginning iPhone programmer, and is the best supplemental material to Apple’s own documentation.”

—Alex C. Schaefer, Lead Programmer, ApolloIM, iPhone Application Development Specialist, MeLLmo, Inc

“Erica’s book is a truly great resource for Cocoa Touch developers. This book goes far beyond the documentation on Apple’s Web site, and she includes methods that give the developer a deeper understanding of the iPhone OS, by letting them glimpse at what’s going on behind the scenes on this incredible mobile platform.”

—John Zorko, Sr. Software Engineer, Mobile Devices

The iPhone and iPod touch aren’t just attracting millions of new users; their breakthrough development platform enables programmers to build tomorrow’s killer applications. If you’re getting started with iPhone programming, this book brings together tested, ready-to-use code for hundreds of the challenges you’re most likely to encounter. Use this fully documented, easy-to-customize code to get productive fast—and focus your time on the specifics of your application, not boilerplate tasks.

Leading iPhone developer Erica Sadun begins by exploring the iPhone delivery platform and SDK, helping you set up your development environment, and showing how iPhone applications are constructed. Next, she offers single-task recipes for the full spectrum of iPhone/iPod touch programming jobs:

  • Utilize views and tables
  • Organize interface elements
  • Alert and respond to users
  • Access the Address Book (people), Core Location (places), and Sensors (things)
  • Connect to the Internet and Web services
  • Display media content
  • Create secure Keychain entries
  • And much more

You’ll even discover how to use Cover Flow to create gorgeous visual selection experiences that put scrolling lists to shame!

This book is organized for fast access: related tasks are grouped together, and you can jump directly to the right solution, even if you don’t know which class or framework to use. All code is based on Apple’s publicly released iPhone SDK, not a beta. No matter what iPhone projects come your way, The iPhone Developer’s Cookbook will be your indispensable companion.

Read More Show Less

Product Details

  • ISBN-13: 9780321555458
  • Publisher: Addison-Wesley
  • Publication date: 10/27/2008
  • Series: Developer's Library
  • Pages: 356
  • Product dimensions: 6.90 (w) x 8.90 (h) x 1.00 (d)

Meet the Author

Erica Sadun has written, coauthored, and contributed to about three dozen books about technology, particularly in the areas of programming, digital video, and digital photography. An unrepentant geek, Sadun has never met a gadget she didn’t need. Her checkered past includes run-ins with NeXT, Newton, iPhone, and myriad successful and unsuccessful technologies. When not writing, she and her geek husband parent three adorable geeks-in-training, who regard their parents with restrained bemusement.

Read More Show Less

Table of Contents

Preface xvii

Acknowledgments xxi

About the Author xxii

1 Introducing the iPhone SDK 1

Apple’s iPhone SDK 1

Assembling iPhone Projects 2

iPhone Application Components 4

Application Folder Hierarchy 4

The Executable 4

The Info.plist File 4

The Icon and Default Images 6

XIB (NIB) files 6

Files Not Found in the Application Bundle 7

Sandboxes 7

Platform Limitations 8

Storage Limits 8

Data Access Limits 8

Memory Limits 8

Interaction Limits 9

Energy Limits 9

Application Limits 9

User Behavior Limits 10

SDK Limitations 10

Programming Paradigms 11

Object-Oriented Programming 11

Model-View-Controller 11

Building an iPhone Application Skeleton 18

The Hello World Application 19

The Classes 19

The Code 20

A Note About Sample Code and Memory Management 20

Building Hello World 23

Create an iPhone Project 23

Running the Skeleton 24

Customize the iPhone Project 24

Editing Identification Information 25

Using the Debugger 26

Apple’s iPhone Developer Program 28

Development Phones 28

Application Identifiers 29

From Xcode to Your iPhone: The Organizer Interface 30

Projects and Sources List 30

Devices List 31

Summary Tab 31

Console Tab 31

Crash Logs Tab 31

Screenshot Tab 32

About Tethering 32

Testing Applications on Your iPhone 32

Compiling for Distribution 33

Using Undocumented API Calls 34

Ad Hoc Distribution 35

Summary 36

2 Views 37

UIView and UIWindow 37

Hierarchy 37

Geometry and Traits 39

Gestures 42

Recipe: Adding Stepwise Subviews 42

Reorienting 44

Recipe: Dragging Views 45

UITouch 46

Adding Persistence 48

Recipe: Clipped Views 51

Balancing Touches with Clipping 53

Accessing Pixel-by-Pixel Values 54

Recipe: Detecting Multitouch 56

UIView Animations 59

Building UIView Animation Blocks 59

Recipe: Fading a View In and Out 60

Recipe: Swapping Views 62

Recipe: Flipping Views 64

Recipe: Applying CATransitions to Layers 66

Undocumented Animation Types 67

General Core Animation Calls 68

Recipe: Swiping Views 69

Recipe: Transforming Views 72

Centering Landscape Views 74

Summary 74

3 View Controllers 77

View Management 77

Core Classes 77

Specialized Classes 78

Creating a UIViewController 79

Working with Interface Builder to Build Views for

UIViewControllers 81

Temperature Conversion Example 81

Loading XIB Files Directly 90

Navigation Controllers 91

Setting Up a Navigation Controller 91

Pushing and Popping View Controllers 92

The Navigation Item Class 92

Recipe: Building a Simple Two-Item Menu 93

Recipe: Adding a Segmented Control 95

Recipe: Adding a UIToolbar to a Navigation Bar 97

Recipe: Navigating Between View Controllers 100

Popping Back to the Root 102

Loading a View Controller Array 102

Tab Bars 103

Summary 106

4 Alerting Users 107

Talking Directly to Your User Through Alerts 107

Logging Your Results 108

Building Alerts 109

Displaying the Alert 110

Recipe: Creating Multiline Button Displays 110

Recipe: Autotimed No-Button Alerts 112

Recipe: Soliciting Text Input from the User 113

Recipe: Presenting Simple Menus 115

“Please Wait”: Showing Progress to Your User 117

Recipe: Invoking the Basic Undocumented UIProgressHUD 117

Recipe: Using UIActivityIndicatorView 119

Recipe: Building a UIProgressView 121

Recipe: Adding Custom, Tappable Overlays 123

Recipe: Building a Scroll-Down Alert 127

Recipe: Adding Status Bar Images 131

Adding Application Badges 132

Recipe: Simple Audio Alerts 134

Vibration 136

Summary 136

5 Basic Tables 139

Introducing UITableView and UITableViewController 139

Creating the Table 140

What the UITableViewController Does 141

Recipe: Creating a Simple List Table 142

Data Source Functions 142

Reusing Cells 143

Font Table Sample 143

Recipe: Creating a Table-Based Selection Sheet 145

Recipe: Loading Images into Table Cells 149

Recipe: Setting a Cell’s Text Traits 151

Removing Cell Selections 152

Recipe: Creating Complex Cells 153

Recipe: Creating Checked Selections 155

Recipe: Deleting Cells 157

Creating and Displaying Remove Controls 157

Dismissing Remove Controls 158

Handling Delete Requests 158

Swiping Cells 158

Adding Cells 159

Recipe: Reordering Cells 161

Recipe: Working with Disclosures 162

Summary 164

6 Advanced Tables 165

Recipe: Grouping Table Selections 165

Building a Section-Based Data Source 166

Adding Section Headers 170

Recipe: Building a Section Table with an Index 171

Recipe: Custom Cell Backgrounds 172

Customizing the Table View 176

Recipe: Creating Alternate Blue and White Cells 177

Recipe: Framing Tables 179

Recipe: Adding Coupled Cell Controls 180

Recipe: Building a Multiwheel Table 182

Creating the UIPickerView 183

Recipe: Using the UIDatePicker 186

Creating the Date Picker 186

Recipe: Creating Fully Customized Group Tables 189

Creating Grouped Preferences Tables 189

Summary 195

7 Media 197

Recipe: Browsing the Documents Folder by File Type 197

Locating Documents 198

Loading and Viewing Images 200

Recipe: Displaying Small Images 201

Recipe: Using a UIWebView to Display Images 203

Displaying Web Pages with UIWebView 205

Recipe: Browsing Your Image Library 206

Recipe: Selecting and Customizing Images from the Camera Roll 209

Recipe: Snapping Pictures with the iPhone Camera 212

Working with iPhone Audio 214

Recipe: Playing Audio with Celestial 215

Recipe: Using the Media Player for Audio and Video Playback 217

Recipe: Recording Audio 219

Reading in Text Data 227

Displaying Property Lists 227

Recovering Media from Backup Files 228

Summary 229

8 Controls 231

Recipe: Building Simple Buttons 231

The UIButton class 232

Building Custom Buttons 233

Glass Buttons 236

Recipe: Adding Animated Elements to Buttons 236

Recipe: Animating Button Responses 238

Recipe: Customizing Switches 239

Customizing UIAlertView Buttons 241

Recipe: Adding Custom Slider Thumbs 242

Adding Text to the Slider 246

Recipe: Dismissing a UITextField Keyboard 246

Recipe: Dismissing UITextView Keyboards 248

Recipe: Adding an Undo Button to Text Views 250

Recipe: Creating a Text View—Based HTML Editor 253

Recipe: Building an Interactive Search Bar 255

Recipe: Adding Callout Views 258

Adding a Page Indicator Control 260

Recipe: Customizing Toolbars 263

Toolbar Tips 266

Summary 267

9 People, Places, and Things 269

Address Book Frameworks 269

Address Book UI 269

Address Book 270

Recipe: Accessing Address Book Image Data 271

Recipe: Displaying Address Book Information 273

Recipe: Browsing the Address Book 274

Browsing for (Only) E-Mail Addresses 277

Adding New Contacts 277

Core Location 278

How Core Location Works 278

Recipe: Core Location in a Nutshell 280

Recipe: Reverse Geocoding to an Address 283

Recipe: Accessing Maps Using Core Location Data 286

Recipe: Accessing Core Device Information 288

Recipe: Enabling and Disabling the Proximity Sensor 289

Recipe: Using Acceleration to Locate “Up” 290

Recipe: Using Acceleration to Move Onscreen Objects 292

Summary 295

10 Connecting to Services 297

Recipe: Adding Custom Settings Bundles 297

Declaring Application Settings 297

Recipe: Subscribing Applications to Custom URL Schemes 302

Recipe: Checking Your Network Status 304

Testing the Network Status 304

Recovering a Local IP Address 305

Querying Site IP Addresses 306

Checking Site Availability 307

Recipe: Interacting with iPhone Databases 308

Recipe: Converting XML into Trees 311

Recipe: Storing and Retrieving Keychain Items 313

Storing Multiple Keychain Values 318

Keychain Persistence 319

Sending and Receiving Files 320

Recipe: Building a Simple Web-Based Server 321

Push Notifications 325

Summary 326

11 One More Thing: Programming Cover Flow 327

The UICoverFlowLayer Class 327

Building a Cover Flow View 329

Building a Cover Flow View Controller 331

Cover Flow Data Source Methods 332

Cover Flow Delegate Methods 333

Summary 336

Index 357

Read More Show Less

Preface

Preface

Few platforms match the iPhone’s unique developer technologies. It combines OS X-based mobile computing with an innovative multitouch screen, location awareness, an onboard accelerometer, and more. When Apple introduced the iPhone Cocoa Touch SDK beta in early March 2008, developers responded in numbers that brought Apple’s servers to its knees. Apple delivered more than one hundred thousand SDK downloads in less than one week. The iPhone Developer’s Cookbook was written to address this demand, providing an accessible resource for those new to iPhone programming.

Who This Book Is For

This book is written for new iPhone developers with projects to get done and a new unfamiliar SDK in their hands. Although each programmer brings different goals and experiences to the table, most developers end up solving similar tasks in their development work: “How do I build a table?”; “How do I create a secure keychain entry?”; “How do I search the Address Book?”; “How do I move between views?”; and “How do I use Core Location?”

The iPhone Developer’s Cookbook is aimed squarely at anyone just getting started with iPhone programming. With its clear, fully documented examples, it will get you up to speed and working productively. It presents already tested ready-to-use solutions, letting programmers focus on the specifics of their application rather than on boilerplate tasks.

How This Book Is Structured

This book offers single-task recipes for the most common issues new iPhone developers face: laying out interface elements, responding to users, accessing local data sources, and connecting to the Internet. The cookbook approach delivers cut-and-paste convenience. Programmers can add source recipes into their projects and then customize them to their needs. Each chapter groups related tasks together. Readers can jump directly to the kind of solution they’re looking for without having to decide which class or framework best matches that problem.

Here’s a rundown of what you’ll find in this book’s chapters:

  • Chapter 1: Getting Started with the iPhone SDK

    Chapter 1 introduces the iPhone SDK and explores the iPhone as a delivery platform, limitations and all. It explains the breakdown of the standard iPhone application and enables you to build your first Hello World style samples.

  • Chapter 2: Views

    Chapter 2 introduces iPhone views, objects that live on your screen. You see how to lay out, create, and order your views to create backbones for your iPhone applications. You read about view hierarchies, geometries, and animations as well as how users can interact with views through touch.

  • Chapter 3: View Controllers

    The iPhone paradigm in a nutshell is this: small screen, big virtual worlds. In Chapter 3, you discover the various UIViewController classes that enable you to enlarge and order the virtual spaces your users interact with. You learn how to let these powerful objects perform all the heavy lifting when navigating between iPhone application screens.

  • Chapter 4: Alerting Users

    The iPhone offers many ways to provide users with a heads up, from pop-up dialogs and progress bars to audio pings and status bar updates. Chapter 4 shows how to build these indications into your applications and expand your user-alert vocabulary.

  • Chapter 5: Basic Tables

    Tables provide an interaction class that works particularly well on a small, cramped device. Many, if not most, apps that ship with the iPhone and iPod touch center on tables, including Settings, YouTube, Stocks, and Weather. Chapter 5 shows how iPhone tables work, what kinds of tables are available to you as a developer, and how you can use table features in your own programs.

  • Chapter 6: Advanced Tables

    iPhone tables do not begin and end with simple scrolling lists. You can build tables with titled sections, with multiple scrolling columns, and more. You can add controls such as switches, create translucent cell backgrounds, and include custom fonts. Chapter 6 starts from where “Basic Tables” left off. It introduces advanced table recipes for you to use in your iPhone programs.

  • Chapter 7: Media

    As you’d expect, the iPhone can load and display media from a wide variety of formats. It does music; it does movies. It handles images and Web pages. You can present PDF documents and photo albums and more. Chapter 7 shows way after way that you can import or download data into your program and display that data using the iPhone’s multitouch interface.

  • Chapter 8: Control

    The UIControl class provides the basis for many iPhones interactive elements, including buttons, text fields, sliders, and switches. Chapter 8 introduces controls and their use, both through well-documented SDK calls and through less-­documented ones.

  • Chapter 9: People, Places, and Things

    In addition to standard user interface controls and media components that you’d see on any computer, the iPhone SDK provides a number of tightly focused developer solutions specific to iPhone and iPod touch delivery. Chapter 9 introduces the most useful of these, including Address Book access (“people”), core location (“places”), and sensors (“things”).

  • Chapter 10: Connecting to Services

    As an Internet-connected device, the iPhone is particularly suited to subscribing to Web-based services. Apple has lavished the platform with a solid grounding in all kinds of network computing services and their supporting technologies. The iPhone SDK handles sockets, password keychains, SQL access, XML processing, and more. Chapter 10 surveys common techniques for network computing and offering recipes that simplify day-to-day tasks.

  • Chapter 11: One More Thing: Programming Cover Flow

    Although Cover Flow is not officially included in the iPhone SDK, it offers one of the nicest and most beautiful features of the iPhone experience. With Cover Flow, you can offer your users a gorgeously intense visual selection experience that puts standard scrolling lists to shame. Chapter 11 introduces Cover Flow and shows how you can use it in your applications.

Prerequisites

Here are basics you need on hand to begin programming for the iPhone or iPod touch:

  • A copy of Apple’s iPhone SDK. Download your copy of the iPhone SDK from Apple’s iPhone Dev Center (http://developer.apple.com/iphone/). You must join Apple’s (free) developer program before you download.
  • An iPhone or iPod touch. Although Apple supplies a simulator as part of its SDK, you really do need to have an actual unit to test on if you’re going to develop any serious software. You’ll be able to use the cable that shipped with your iPhone or iPod touch to tether your unit to the computer and install the software you’ve built.
  • An Apple iPhone Developer License. You will not be able to test your software on an actual iPhone or iPod touch until you join Apple’s iPhone Developer program (http://developer.apple.com/iphone/program). Members receive a certificate that allows them to sign their applications and download them to the platforms in question for testing and debugging. The program costs $99/year for individuals and companies, $299/year for in-house enterprise development.
  • An Intel-based Macintosh running Leopard. The SDK requires a Macintosh running Leopard OS X 10.5.3 or later. Apple requires an Intel-based computer in 32-bit mode. Many features do not work properly on PPC-based Macs or Intel Macs in 64-bit mode. Reserve plenty of disk space and at least 1GB of RAM.
  • At least one available USB 2.0 port. This enables you to tether your development iPhone or iPod touch to your computer for file transfer and testing.
  • An Internet connection. This connection enables you to test your programs with a live WiFi connection as well as with EDGE.
  • Familiarity with Objective-C. The SDK is built around Objective-C 2.0. The language is based on standard C with object-oriented extensions. If you have any object-oriented and C background, making the move to Objective-C is both quick and simple. Consult any Objective-C/Cocoa reference book to get up to speed.

Note - Although the SDK supports development for the iPhone and iPod touch, as well as possible yet-to-be-announced platforms, this book refers to the target platform as iPhone for the sake of simplicity. When developing for the touch, most material is applicable. This excludes certain obvious features such as telephony and onboard speakers. This book attempts to note such exceptions in the manuscript.


Contacting the Author

If you have any comments or questions about this book, please drop me an e-mail ­message at erica@ericasadun.com or stop by http://www.ericasadun.com. My Web site hosts many of the applications discussed in this book. Please feel free to visit, download ­software, read documentation, and leave your comments.

© Copyright Pearson Education. All rights reserved.

Read More Show Less

Customer Reviews

Be the first to write a review
( 0 )
Rating Distribution

5 Star

(0)

4 Star

(0)

3 Star

(0)

2 Star

(0)

1 Star

(0)

Your Rating:

Your Name: Create a Pen Name or

Barnes & Noble.com Review Rules

Our reader reviews allow you to share your comments on titles you liked, or didn't, with others. By submitting an online review, you are representing to Barnes & Noble.com that all information contained in your review is original and accurate in all respects, and that the submission of such content by you and the posting of such content by Barnes & Noble.com does not and will not violate the rights of any third party. Please follow the rules below to help ensure that your review can be posted.

Reviews by Our Customers Under the Age of 13

We highly value and respect everyone's opinion concerning the titles we offer. However, we cannot allow persons under the age of 13 to have accounts at BN.com or to post customer reviews. Please see our Terms of Use for more details.

What to exclude from your review:

Please do not write about reviews, commentary, or information posted on the product page. If you see any errors in the information on the product page, please send us an email.

Reviews should not contain any of the following:

  • - HTML tags, profanity, obscenities, vulgarities, or comments that defame anyone
  • - Time-sensitive information such as tour dates, signings, lectures, etc.
  • - Single-word reviews. Other people will read your review to discover why you liked or didn't like the title. Be descriptive.
  • - Comments focusing on the author or that may ruin the ending for others
  • - Phone numbers, addresses, URLs
  • - Pricing and availability information or alternative ordering information
  • - Advertisements or commercial solicitation

Reminder:

  • - By submitting a review, you grant to Barnes & Noble.com and its sublicensees the royalty-free, perpetual, irrevocable right and license to use the review in accordance with the Barnes & Noble.com Terms of Use.
  • - Barnes & Noble.com reserves the right not to post any review -- particularly those that do not follow the terms and conditions of these Rules. Barnes & Noble.com also reserves the right to remove any review at any time without notice.
  • - See Terms of Use for other conditions and disclaimers.
Search for Products You'd Like to Recommend

Recommend other products that relate to your review. Just search for them below and share!

Create a Pen Name

Your Pen Name is your unique identity on BN.com. It will appear on the reviews you write and other website activities. Your Pen Name cannot be edited, changed or deleted once submitted.

 
Your Pen Name can be any combination of alphanumeric characters (plus - and _), and must be at least two characters long.

Continue Anonymously
Sort by: Showing all of 3 Customer Reviews
  • Posted June 6, 2009

    more from this reviewer

    I Also Recommend:

    A good book to start if you need to develop for iPhone!

    A nice book, direct, and takes you right to the point.
    You may need to have previous knowledge with Objective-C though.
    A great value for the price.

    1 out of 1 people found this review helpful.

    Was this review helpful? Yes  No   Report this review
  • Anonymous

    Posted June 22, 2009

    No text was provided for this review.

  • Anonymous

    Posted July 29, 2009

    No text was provided for this review.

Sort by: Showing all of 3 Customer Reviews

If you find inappropriate content, please report it to Barnes & Noble
Why is this product inappropriate?
Comments (optional)