iPhone SDK 3 Programming: Advanced Mobile Development for Apple iPhone and iPod touch

Book description

Get the expert guidance you need to begin building native applications for Apple's new iPhone 3G as well as the iPod Touch

Apple's iPhone is the hottest mobile device on the planet. More than one million iPhone 3G phones were sold in the first three days of release and millions more are sure to be in the hands of iPhone fans each year. Apple's iPhone SDK has been updated and includes more than one thousand new APIs that developers will want to get their hands on.

iPhone SDK 3 Programming shows you how to build great applications for the iPhone and iPod Touch. Inside, veteran mobile developer and Bell Labs scientist Maher Ali begins with a foundational introduction to Objective-C and Cocoa programming, and then guides you through building programs with Apple's iPhone SDK 3.

  • Covers the complete application development process, and highlights all the key device features including the camera, location awareness, and more

  • Completely revised and redesigned with more than 100 new pages of content

  • iPhone's new SDK release contains more than one thousand new APIs you will want to use right away

  • Includes a focused introduction to the Objective-C language and Cocoa frameworks that new iPhone developers need

With this advanced resource, you'll get the expert guidance you need to begin building native applications for Apple's new iPhone 3G as well as the iPod Touch.

Table of contents

  1. Copyright
  2. PREFACE
    1. Is this book for you?
    2. What else do you need?
    3. Conventions used in this book
    4. Organization
  3. 1. Getting Started
    1. 1.1. SDK and IDE Basics
      1. 1.1.1. Obtaining and installing the SDK
      2. 1.1.2. Creating a project
      3. 1.1.3. Familiarizing yourself with the IDE
      4. 1.1.4. Looking closely at the generated code
    2. 1.2. Creating Interfaces
      1. 1.2.1. Interface Builder
    3. 1.3. Using the Debugger
    4. 1.4. Getting More Information
    5. 1.5. Summary
      1. 1.5.1. Problems
  4. 2. Objective-C and Cocoa
    1. 2.1. Classes
      1. 2.1.1. Class declaration
      2. 2.1.2. How do I use other declarations?
      3. 2.1.3. Class definition
      4. 2.1.4. Method invocation and definition
      5. 2.1.5. Important types
      6. 2.1.6. Important Cocoa classes
    2. 2.2. Memory Management
      1. 2.2.1. Creating and deallocating objects
      2. 2.2.2. Preventing memory leaks
    3. 2.3. Protocols
      1. 2.3.1. Protocol conformance
    4. 2.4. Properties
      1. 2.4.1. Property declaration
      2. 2.4.2. Circular references
    5. 2.5. Categories
    6. 2.6. Posing
    7. 2.7. Exceptions and Errors
      1. 2.7.1. Exceptions
        1. 2.7.1.1. Exception example
        2. 2.7.1.2. Creating exceptions
        3. 2.7.1.3. Nesting exceptions
      2. 2.7.2. Errors
        1. 2.7.2.1. Error example
        2. 2.7.2.2. Creating an NSError instance
    8. 2.8. Key-value coding (KVC)
      1. 2.8.1. An example illustrating KVC
    9. 2.9. Multithreading
    10. 2.10. Notifications
    11. 2.11. The Objective-C Runtime
      1. 2.11.1. Required header files
      2. 2.11.2. The NSObject class
      3. 2.11.3. Objective-C methods
      4. 2.11.4. Examples
        1. 2.11.4.1. Obtaining instance and class methods
        2. 2.11.4.2. Querying response to messages
        3. 2.11.4.3. Replacing existing implementation
        4. 2.11.4.4. Patching methods
        5. 2.11.4.5. Obtaining all methods defined by a class
        6. 2.11.4.6. Adding a new method
        7. 2.11.4.7. Sending a message to an object
        8. 2.11.4.8. Accessing instance variables
        9. 2.11.4.9. Creating new classes dynamically
        10. 2.11.4.10. Alternatives to executing methods
        11. 2.11.4.11. Forwarding messages to other objects
    12. 2.12. Summary
    13. 2.13. Problems
  5. 3. Collections
    1. 3.1. Arrays
      1. 3.1.1. Immutable copy
      2. 3.1.2. Mutable copy
      3. 3.1.3. Deep copy
      4. 3.1.4. Sorting an array
    2. 3.2. Sets
      1. 3.2.1. Immutable sets
      2. 3.2.2. Mutable sets
      3. 3.2.3. Additional important methods
    3. 3.3. Dictionaries
      1. 3.3.1. Additional important methods
    4. 3.4. Summary
    5. 3.5. Problems
  6. 4. Anatomy of an iPhone Application
    1. 4.1. Hello World Application
      1. 4.1.1. Create a main.m file
      2. 4.1.2. Create the application delegate class
      3. 4.1.3. Create the user interface subclasses
    2. 4.2. Building the Hello World Application
    3. 4.3. Summary
    4. 4.4. Problems
  7. 5. The View
    1. 5.1. View Geometry
      1. 5.1.1. Useful geometric type definitions
      2. 5.1.2. The UIScreen class
      3. 5.1.3. The frame and center properties
      4. 5.1.4. The bounds property
    2. 5.2. The View Hierarchy
    3. 5.3. The Multitouch Interface
      1. 5.3.1. The UITouch class
      2. 5.3.2. The UIEvent class
      3. 5.3.3. The UIResponder class
      4. 5.3.4. Handling a swipe
      5. 5.3.5. More advanced gesture recognition
    4. 5.4. Animation
      1. 5.4.1. Using the UIView class animation support
        1. 5.4.1.1. Using an animation delegate
      2. 5.4.2. Sliding view
      3. 5.4.3. Flip animation
      4. 5.4.4. Transition animation
    5. 5.5. Drawing
    6. 5.6. Summary
    7. 5.7. Problems
  8. 6. Controls
    1. 6.1. The Foundation of all Controls
      1. 6.1.1. UIControl attributes
      2. 6.1.2. Target-action mechanism
    2. 6.2. The Text Field
      1. 6.2.1. Interacting with the keyboard
      2. 6.2.2. The delegate
      3. 6.2.3. Creating and working with a UITextField
    3. 6.3. Sliders
    4. 6.4. Switches
    5. 6.5. Buttons
    6. 6.6. Segmented Controls
    7. 6.7. Page Controls
    8. 6.8. Date Pickers
    9. 6.9. Summary
    10. 6.10. Problems
  9. 7. View Controllers
    1. 7.1. The Simplest View Controller
      1. 7.1.1. The view controller
      2. 7.1.2. The view
      3. 7.1.3. The application delegate
      4. 7.1.4. Summary: creating a simple MVC application
    2. 7.2. Radio Interfaces
      1. 7.2.1. A detailed example
      2. 7.2.2. Some comments on tab bar controllers
    3. 7.3. Navigation Controllers
      1. 7.3.1. A detailed example
        1. 7.3.1.1. The view controller
        2. 7.3.1.2. The view
        3. 7.3.1.3. The application delegate
      2. 7.3.2. Customization
        1. 7.3.2.1. Navigation item
    4. 7.4. Modal View Controllers
      1. 7.4.1. A detailed example
    5. 7.5. Summary
    6. 7.6. Problems
  10. 8. Special-Purpose Views
    1. 8.1. Picker View
      1. 8.1.1. The delegate
      2. 8.1.2. An example
    2. 8.2. Progress Views
      1. 8.2.1. An example
    3. 8.3. Scroll View
    4. 8.4. Text View
      1. 8.4.1. The delegate
      2. 8.4.2. An example
    5. 8.5. Alert View
    6. 8.6. Action Sheet
    7. 8.7. Web View
      1. 8.7.1. A simple web view application
      2. 8.7.2. Viewing local files
      3. 8.7.3. Evaluating JavaScript
      4. 8.7.4. The web view delegate
    8. 8.8. Summary
    9. 8.9. Problems
  11. 9. Table View
    1. 9.1. Overview
    2. 9.2. The Simplest Table View Application
    3. 9.3. A Table View with both Images and Text
    4. 9.4. A Table View with Section Headers and Footers
    5. 9.5. A Table View with the Ability to Delete Rows
    6. 9.6. A Table View with the Ability to Insert Rows
    7. 9.7. Reordering Table Rows
    8. 9.8. Presenting Hierarchical Information
      1. 9.8.1. Detailed example
    9. 9.9. Grouped Table Views
    10. 9.10. Indexed Table Views
    11. 9.11. Dynamic Table Views
    12. 9.12. Whitening Text in Custom Cells
    13. 9.13. Summary
    14. 9.14. Problems
  12. 10. File Management
    1. 10.1. The Home Directory
    2. 10.2. Enumerating a Directory
    3. 10.3. Creating and Deleting a Directory
    4. 10.4. Creating Files
    5. 10.5. Retrieving and Changing Attributes
      1. 10.5.1. Retrieving attributes
      2. 10.5.2. Changing attributes
    6. 10.6. Working with Resources and Low-level File Access
    7. 10.7. Summary
    8. 10.8. Problems
  13. 11. Working with Databases
    1. 11.1. Basic Database Operations
      1. 11.1.1. Opening, creating, and closing databases
      2. 11.1.2. Table operations
    2. 11.2. Processing Row Results
    3. 11.3. Prepared Statements
      1. 11.3.1. Preparation
      2. 11.3.2. Execution
      3. 11.3.3. Finalization
      4. 11.3.4. Putting it together
    4. 11.4. User-defined Functions
    5. 11.5. Storing BLOBs
    6. 11.6. Retrieving BLOBs
    7. 11.7. Summary
    8. 11.8. Problems
  14. 12. XML Processing
    1. 12.1. XML and RSS
      1. 12.1.1. XML
      2. 12.1.2. RSS
      3. 12.1.3. Configuring the XCode project
    2. 12.2. Document Object Model (DOM)
    3. 12.3. Simple API for XML (SAX)
    4. 12.4. An RSS Reader Application
    5. 12.5. Putting It Together
    6. 12.6. Summary
    7. 12.7. Problems
  15. 13. Location Awareness
    1. 13.1. The Core Location Framework
      1. 13.1.1. The CLLocation class
    2. 13.2. A Simple Location-aware Application
    3. 13.3. Google Maps API
      1. 13.3.1. A geocoding application
    4. 13.4. A Tracking Application with Maps
    5. 13.5. Working with ZIP Codes
    6. 13.6. Working with the Map Kit API
      1. 13.6.1. The MKMapView class
      2. 13.6.2. The MKCoordinateRegion structure
      3. 13.6.3. The MKAnnotation protocol
      4. 13.6.4. The MKAnnotationView class
        1. 13.6.4.1. The callout view
      5. 13.6.5. The MKUserLocation class
      6. 13.6.6. The MKPinAnnotationView class
    7. 13.7. Summary
    8. 13.8. Problems
  16. 14. Working with Devices
    1. 14.1. Working with the Accelerometer
      1. 14.1.1. Basic accelerometer values
      2. 14.1.2. Example
    2. 14.2. Working with Audio
      1. 14.2.1. Playing short audio files
        1. 14.2.1.1. Example
      2. 14.2.2. Recording audio files
      3. 14.2.3. Playing audio files
      4. 14.2.4. Using the media picker controller
        1. 14.2.4.1. The MPMediaPickerController class
        2. 14.2.4.2. The media controller delegate
        3. 14.2.4.3. The MPMediaItem class
        4. 14.2.4.4. Putting it together
      5. 14.2.5. Searching the iPod library
        1. 14.2.5.1. Grouping method
        2. 14.2.5.2. Media property predicate
    3. 14.3. Playing Video
      1. 14.3.1. Using the MPMoviePlayerController class
    4. 14.4. Accessing Device Information
    5. 14.5. Taking and Selecting Pictures
      1. 14.5.1. Overall approach
      2. 14.5.2. Detailed example
        1. 14.5.2.1. Presenting the image picker
        2. 14.5.2.2. Handling successful picking of the photo
    6. 14.6. Monitoring Device Battery
      1. 14.6.1. Battery level
      2. 14.6.2. Battery state
      3. 14.6.3. Battery state and level notifications
      4. 14.6.4. Putting it together
    7. 14.7. Accessing the Proximity Sensor
      1. 14.7.1. Enabling proximity monitoring
      2. 14.7.2. Subscribing to proximity change notification
      3. 14.7.3. Retrieving the proximity state
    8. 14.8. Summary
    9. 14.9. Problems
  17. 15. Internationalization
    1. 15.1. String Localization
    2. 15.2. Date Formatting
      1. 15.2.1. Custom formats
    3. 15.3. Number Formatting
    4. 15.4. Sorted List of Countries
    5. 15.5. Summary
    6. 15.6. Problems
  18. 16. Custom UI Components
    1. 16.1. Text Field Alert View
    2. 16.2. Table Alert View
    3. 16.3. Progress Alert View
    4. 16.4. Summary
    5. 16.5. Problems
  19. 17. Advanced Networking
    1. 17.1. Determining Network Connectivity
      1. 17.1.1. Determining network connectivity via EDGE or GPRS
      2. 17.1.2. Determining network connectivity in general
      3. 17.1.3. Determining network connectivity via WiFi
    2. 17.2. Uploading Multimedia Content
    3. 17.3. Computing MD5 Hash Value
    4. 17.4. Multithreaded Downloads
      1. 17.4.1. The application
        1. 17.4.1.1. The Internet Resource class
        2. 17.4.1.2. The Table View controller
    5. 17.5. Push Notification
      1. 17.5.1. Configuring push notification on the server
        1. 17.5.1.1. Configuring the App ID
        2. 17.5.1.2. Configuring the App ID for notification
        3. 17.5.1.3. Generating the SSL certificate
        4. 17.5.1.4. Installing the SSL certificate on the server
      2. 17.5.2. Configuring the client
        1. 17.5.2.1. Creating a provisioning profile
        2. 17.5.2.2. Installing the provisioning profile on the device and XCode
        3. 17.5.2.3. Configuring the XCode application
      3. 17.5.3. Coding the client
        1. 17.5.3.1. Registering for push notification
        2. 17.5.3.2. Receiving notifications
      4. 17.5.4. Coding the server
    6. 17.6. Sending Email
      1. 17.6.1. Using the mail composition view controller
        1. 17.6.1.1. Checking email capability
        2. 17.6.1.2. Creating the email composition controller
        3. 17.6.1.3. Adding the subject line
        4. 17.6.1.4. Adding the recipients
        5. 17.6.1.5. Adding the other recipients
        6. 17.6.1.6. Setting up the message body
        7. 17.6.1.7. Adding attachments
        8. 17.6.1.8. The delegate
    7. 17.7. Summary
    8. 17.8. Problems
  20. 18. Working with the Address Book Database
    1. 18.1. Introduction
    2. 18.2. Property Types
    3. 18.3. Accessing Single-Value Properties
      1. 18.3.1. Retrieving single-value properties
      2. 18.3.2. Setting single-value properties
    4. 18.4. Accessing Multi-Value Properties
      1. 18.4.1. Retrieving multi-value properties
      2. 18.4.2. Setting multi-value properties
    5. 18.5. Person and Group Records
    6. 18.6. Address Book
    7. 18.7. Multithreading and Identifiers
    8. 18.8. Person Photo Retriever Application
    9. 18.9. Using the ABUnknownPersonViewController Class
    10. 18.10. Using the ABPeoplePickerNavigationController Class
    11. 18.11. Using the ABPersonViewController Class
    12. 18.12. Using the ABNewPersonViewController Class
    13. 18.13. Summary
    14. 18.14. Problems
  21. 19. Core Data
    1. 19.1. Core Data Application Components
    2. 19.2. Key Players
      1. 19.2.1. Entity
      2. 19.2.2. Managed object model
      3. 19.2.3. Persistent store coordinator
      4. 19.2.4. Managed object context
      5. 19.2.5. Managed object
      6. 19.2.6. Summary
    3. 19.3. Using the Modeling Tool
    4. 19.4. Create, Read, Update and Delete (CRUD)
      1. 19.4.1. Create
      2. 19.4.2. Delete
      3. 19.4.3. Read and update
        1. 19.4.3.1. Unconditional fetch
        2. 19.4.3.2. Conditional fetch
        3. 19.4.3.3. Sorted fetch
    5. 19.5. Working with Relationships
    6. 19.6. A Search Application
      1. 19.6.1. The UISearchDisplayController class
      2. 19.6.2. Main pieces
    7. 19.7. Summary
    8. 19.8. Problems
  22. 20. Undo Management
    1. 20.1. Understanding Undo Management
      1. 20.1.1. Basic idea
      2. 20.1.2. Creating an undo manager
      3. 20.1.3. Registering an undo operation
      4. 20.1.4. Hooking into the undo management mechanism
        1. 20.1.4.1. Using undo with view controllers
      5. 20.1.5. Enabling shake to edit behavior
    2. 20.2. Detailed Example
      1. 20.2.1. The view controller class
      2. 20.2.2. First responder status
      3. 20.2.3. Editing mode and the NSUndoManager instance
      4. 20.2.4. Registering undo actions
    3. 20.3. Wrapping Up
    4. 20.4. Summary
    5. 20.5. Problems
  23. 21. Copy and Paste
    1. 21.1. Pasteboards
      1. 21.1.1. System pasteboards
      2. 21.1.2. Creating pasteboards
      3. 21.1.3. Properties of a pasteboard
    2. 21.2. Pasteboard Items
      1. 21.2.1. Pasteboard items
      2. 21.2.2. Manipulating pasteboard items
        1. 21.2.2.1. Convenient methods
    3. 21.3. The Editing Menu
      1. 21.3.1. The standard editing actions
      2. 21.3.2. The UIMenuController class
      3. 21.3.3. The role of the view controller
    4. 21.4. Putting it Together
      1. 21.4.1. The image view
      2. 21.4.2. The view controller
    5. 21.5. Summary
    6. 21.6. Problems
  24. A. Saving and Restoring App State
  25. B. Invoking External Applications
  26. C. App Store Distribution
  27. D. Using XCode
    1. D.1. XCode Shortcuts
    2. D.2. Creating Custom Templates
      1. D.2.1. Changing template macro definitions
    3. D.3. Build-Based Configurations
    4. D.4. Using Frameworks
  28. E. Unit Testing
    1. E.1. Adding a Unit Test Target
    2. E.2. Adapting to Foundation
    3. E.3. The Model
    4. E.4. Writing Unit Tests for the Employee Class
      1. E.4.1. The setUp and tearDown methods
      2. E.4.2. Testing for equality
      3. E.4.3. Testing for nullity
    5. E.5. Adding a Build Dependency
    6. E.6. Running the Tests
  29. F. Working with Interface Builder
    1. F.1. National Debt Clock Application
      1. F.1.1. Creating the project
      2. F.1.2. Creating the view controller class
      3. F.1.3. The application delegate class
      4. F.1.4. Building the UI
        1. F.1.4.1. Adding a navigation controller
        2. F.1.4.2. Adding a root view controller
        3. F.1.4.3. Building the main view of the root controller
        4. F.1.4.4. Linking the UI elements with the code
        5. F.1.4.5. Finishing the view controller class
    2. F.2. Toolbar Application
      1. F.2.1. Writing code
      2. F.2.2. Building the UI
      3. F.2.3. Putting it together
  30. REFERENCES AND BIBLIOGRAPHY
    1. Bibliography

Product information

  • Title: iPhone SDK 3 Programming: Advanced Mobile Development for Apple iPhone and iPod touch
  • Author(s): Maher Ali
  • Release date: August 2009
  • Publisher(s): Wiley
  • ISBN: 9780470683989