Home > Store

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

Register your product to gain access to bonus material or receive a coupon.

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

eBook (Watermarked)

  • Sorry, this book is no longer in print.
  • About Watermarked eBooks
  • This PDF will be accessible from your Account page after purchase and requires PDF reading software, such as Acrobat® Reader®.

    The eBook requires no passwords or activation to read. We customize your eBook by discreetly watermarking it with your name, making it uniquely yours.

    Watermarked eBook FAQ

Not for Sale

Description

  • Copyright 2009
  • Edition: 1st
  • eBook (Watermarked)
  • ISBN-10: 0-321-55351-9
  • ISBN-13: 978-0-321-55351-5

This is the eBook version of the printed book. If the print book includes a CD-ROM, this content is not included within the eBook version.


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.

Sample Content

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

More Information

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.

Overview


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information


To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.

Surveys

Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.

Newsletters

If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information


Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.

Security


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.

Children


This site is not directed to children under the age of 13.

Marketing


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information


If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.

Choice/Opt-out


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information


Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents


California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure


Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.

Links


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact


Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice


We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020