iOS 4 Programming Cookbook

Book description

You can build a variety of amazing apps on the iOS platform—and every one of them presents a unique set of problems. With the recipes in this cookbook, you'll go beyond theory to solve the vexing, real-life issues you’re likely to face when creating apps for the iPhone, iPad, or iPod Touch. Each recipe provides a clear solution and sample code that you can use right away.

You'll find solutions for working with development frameworks in iOS SDK 4 and technologies such as Cocoa, Objective-C, Xcode, and Interface Builder. Whether you have a little or a lot of experience with iOS development, you’ll find the help you need for every phase of the process, from initial idea to completed project.

  • Work with Objective-C classes, objects, properties, delegates, and memory management
  • Construct a user interface with gesture recognizers
  • Develop location-aware applications with the Map Kit and Core Location APIs
  • Build apps that play audio and video, manage calendars and events, access contacts and groups, or tap into the Photo Library
  • Use the Core Motion framework to access the accelerometer and gyroscope
  • Maintain persistent storage for iOS apps with the Core Data framework
  • Create multitasking-aware apps that let users leave and return without losing their place

Publisher resources

View/Submit Errata

Table of contents

  1. Dedication
  2. A Note Regarding Supplemental Files
  3. Preface
    1. Audience
    2. Organization of This Book
    3. Additional Resources
    4. Conventions Used in This Book
    5. Using Code Examples
    6. We’d Like to Hear from You
    7. Safari® Books Online
    8. Acknowledgments
  4. 1. Working with Objects
    1. 1.0. Introduction
    2. 1.1. Implementing and Using Custom Objects
    3. 1.2. Allocating and Initializing Objects
    4. 1.3. Defining Two or More Methods with the Same Name in an Object
    5. 1.4. Defining and Accessing Properties
    6. 1.5. Managing Properties Manually
    7. 1.6. Reusing a Block of Code
    8. 1.7. Communicating with Objects
    9. 1.8. Invoking the Selectors of an Object Dynamically
    10. 1.9. Managing Memory with the iOS SDK
    11. 1.10. Managing Untyped Objects
  5. 2. Implementing Controllers and Views
    1. 2.0. Introduction
    2. 2.1. Getting and Using the Application Delegate
    3. 2.2. Managing the Views in Your Application
    4. 2.3. Creating Your Application’s GUI
    5. 2.4. Making Your View Controller Available at Runtime
    6. 2.5. Using a View in Your Application’s GUI
    7. 2.6. Managing Master-Detail Views
    8. 2.7. Managing Multiple Views
    9. 2.8. Incorporating and Using Models in the GUI
    10. 2.9. Implementing Navigation Bars
    11. 2.10. Switching from One View to Another
    12. 2.11. Setting the Title on a Navigation Bar
    13. 2.12. Displaying an Image for the Title of the Navigation Bar
    14. 2.13. Creating and Managing Buttons on a Navigation Bar
    15. 2.14. Removing a View from a Navigation Controller
    16. 2.15. Manipulating a Navigation Controller’s Array of View Controllers
    17. 2.16. Incorporating a Tab Bar into Your Application
    18. 2.17. Pop Up Additional Information over iPad UI Elements
  6. 3. Constructing and Using Table Views
    1. 3.0. Introduction
    2. 3.1. Creating a Table View Using Interface Builder
    3. 3.2. Creating a Table View Using Code
    4. 3.3. Assigning an Event Handler to a Table View Using Interface Builder
    5. 3.4. Assigning an Event Handler to a Table View Using Xcode
    6. 3.5. Populating a Table View with Data
    7. 3.6. Receiving and Handling Table View Events
    8. 3.7. Using Different Types of Accessories in a Table View
    9. 3.8. Creating Custom Table View Accessories
    10. 3.9. Customizing the Appearance of a Table View’s Contents
    11. 3.10. Displaying Hierarchical Data
    12. 3.11. Effectively Managing Memory with Table Views
    13. 3.12. Editing and Moving Data in a Table View
    14. 3.13. Enabling Swipe Deletion
    15. 3.14. Grouping Data
  7. 4. Core Location and Maps
    1. 4.0. Introduction
    2. 4.1. Creating a Map Using Interface Builder
    3. 4.2. Creating a Map Using Code
    4. 4.3. Handling the Events of a Map
    5. 4.4. Pinpointing a Device’s Location
    6. 4.5. Displaying Built-in Pins on a Map View
    7. 4.6. Displaying Pins with Different Colors on a Map View
    8. 4.7. Creating and Displaying Custom Pins on a Map View
    9. 4.8. Retrieving Meaningful Addresses Using Spatial Coordinates
    10. 4.9. Retrieving Spatial Coordinates Using Meaningful Addresses
  8. 5. Implementing Gesture Recognizers
    1. 5.0. Introduction
    2. 5.1. Detecting Swipe Gestures
    3. 5.2. Reacting to Rotation Gestures
    4. 5.3. Detecting Panning and Dragging Gestures
    5. 5.4. Detecting Long Press Gestures
    6. 5.5. Responding to Tap Gestures
    7. 5.6. Responding to Pinch Gestures
  9. 6. Networking and XML
    1. 6.0. Introduction
    2. 6.1. Opening and Reading a Local XML File
    3. 6.2. Parsing an XML File into Objects
    4. 6.3. Downloading Files Synchronously
    5. 6.4. Downloading Files Asynchronously
    6. 6.5. Reading and Parsing Remote XML Files
    7. 6.6. Caching Files in Memory
    8. 6.7. Caching Files on Disk
  10. 7. Operations, Threads, and Timers
    1. 7.0. Introduction
    2. 7.1. Running Tasks Synchronously
    3. 7.2. Running Tasks Asynchronously
    4. 7.3. Creating a Dependency Between Tasks
    5. 7.4. Performing a Task After a Delay
    6. 7.5. Performing Periodic Tasks
    7. 7.6. Performing Periodic Tasks Efficiently
    8. 7.7. Initializing Threads Implicitly
    9. 7.8. Exiting Threads and Timers
    10. 7.9. Avoiding Memory Leaks in Threads
  11. 8. Audio and Video
    1. 8.0. Introduction
    2. 8.1. Playing Audio Files
    3. 8.2. Handling Interruptions While Playing Audio Files
    4. 8.3. Recording Audio Files
    5. 8.4. Handling Interruptions While Recording Audio Files
    6. 8.5. Playing Audio over Other Sounds That Are Playing
    7. 8.6. Playing Video Files
    8. 8.7. Capturing Thumbnails from a Video File Asynchronously
    9. 8.8. Accessing the iPod Library in Response to a User Request
  12. 9. Address Book
    1. 9.0. Introduction
    2. 9.1. Accessing the Address Book
    3. 9.2. Retrieving All the People in the Address Book
    4. 9.3. Retrieving Properties of Address Book Entries
    5. 9.4. Inserting a Person Entry in the User’s Address Book
    6. 9.5. Inserting a Group Entry in the User’s Address Book
    7. 9.6. Adding Persons to Groups
    8. 9.7. Searching in the Address Book
    9. 9.8. Retrieving and Setting a Person’s Address Book Image
  13. 10. Camera and the Photo Library
    1. 10.0. Introduction
    2. 10.1. Detecting and Probing the Camera
    3. 10.2. Taking Photos with the Camera
    4. 10.3. Taking Videos with the Camera
    5. 10.4. Storing Photos in the Photo Library
    6. 10.5. Storing Videos in the Photo Library
    7. 10.6. Retrieving Photos and Videos from the Photo Library
    8. 10.7. Retrieving Assets from the Assets Library
    9. 10.8. Editing Videos on an iOS Device
  14. 11. Multitasking
    1. 11.0. Introduction
    2. 11.1. Detecting the Availability of Multitasking
    3. 11.2. Completing a Long-Running Task in the Background
    4. 11.3. Receiving Local Notifications in the Background
    5. 11.4. Playing Audio in the Background
    6. 11.5. Handling Location Changes in the Background
    7. 11.6. Saving and Loading the State of a Multitasking iOS Application
    8. 11.7. Handling Network Connections in the Background
    9. 11.8. Handling Notifications Delivered to a Waking Application
    10. 11.9. Handling Locale Changes in the Background
    11. 11.10. Responding to Changes in an Application’s Settings
    12. 11.11. Opting Out of Background Execution
  15. 12. Core Data
    1. 12.0. Introduction
    2. 12.1. Creating a Core Data Model with Xcode
    3. 12.2. Creating and Using Core Data Model Classes
    4. 12.3. Creating and Saving Data Using Core Data
    5. 12.4. Loading Data Using Core Data
    6. 12.5. Deleting Data Using Core Data
    7. 12.6. Sorting Data Using Core Data
    8. 12.7. Boosting Data Access in Table Views
    9. 12.8. Implementing Relationships with Core Data
  16. 13. Event Kit
    1. 13.0. Introduction
    2. 13.1. Retrieving the List of Calendars
    3. 13.2. Adding Events to Calendars
    4. 13.3. Accessing the Contents of Calendars
    5. 13.4. Removing Events from Calendars
    6. 13.5. Adding Recurring Events to Calendars
    7. 13.6. Retrieving the Attendees of an Event
    8. 13.7. Adding Alarms to Calendars
    9. 13.8. Handling Event Changed Notifications
    10. 13.9. Presenting Event View Controllers
    11. 13.10. Presenting Event Edit View Controllers
  17. 14. Graphics
    1. 14.0. Introduction
    2. 14.1. Drawing Basic Shapes on a Graphics Context
    3. 14.2. Drawing Paths on a Graphics Context
    4. 14.3. Drawing Images on a Graphics Context
    5. 14.4. Capturing the Screen Contents into an Image
    6. 14.5. Drawing Text with Core Graphics
  18. 15. Core Motion
    1. 15.0. Introduction
    2. 15.1. Detecting the Availability of an Accelerometer
    3. 15.2. Detecting the Availability of a Gyroscope
    4. 15.3. Retrieving Accelerometer Data
    5. 15.4. Detecting a Shake on an iOS Device
    6. 15.5. Retrieving Gyroscope Data
  19. Index
  20. About the Author
  21. Colophon
  22. Copyright

Product information

  • Title: iOS 4 Programming Cookbook
  • Author(s): Vandad Nahavandipoor
  • Release date: February 2011
  • Publisher(s): O'Reilly Media, Inc.
  • ISBN: 9781449388225