Cocoa Touch™ for iPhone® OS 3

Book description

Join the gold rush to developing cool iPhone apps with this complete iPhone OS 3 developer’s guide. Professional developer Jiva DeVoe speaks your language, and he talks you through the entire process—from explaining Cocoa Touch and the iPhone SDK to using Xcode and the Game Kit API. Follow step-by-step tutorials, then apply practical tips on signing and selling your applications. Even if you’re new to iPhone development you’ll soon be cranking out great code.

  • Walk through Xcode, Interface Builder, and other key tools

  • Build simple or complex GUIs with navigation and custom views

  • Implement a database with Core Data, and design your schema in Xcode

  • Learn to use the iPhone’s signature multi-touch capabilities in your applications

  • Work with the Apple Push Notification Service

  • Use the Map Kit API to create apps with embedded maps

  • Record audio, play video, and access the iPod Library

  • Set up your developer certificates and code sign your apps

  • Use Store Kit to sell expanded features and content within your apps

  • Whether you're a new iPhone developer or seasoned veteran, this book is the perfect go-to reference for iPhone development-and one of an exciting new series for Apple developers.

    Table of contents

    1. Copyright
    2. About the Author
    3. Credits
    4. Preface
    5. Acknowledgments
    6. I. Getting Started with the iPhone
      1. 1. Getting to Know Your Tools
        1. 1.1. Introducing Xcode
        2. 1.2. Introducing Interface Builder
        3. 1.3. Summary
      2. 2. Building a Basic iPhone Application
        1. 2.1. Creating a Project from a Template
        2. 2.2. Building a Simple GUI
        3. 2.3. Writing a Simple UIViewController
        4. 2.4. Launching on the iPhone
        5. 2.5. Summary
      3. 3. Exploring the Simulator in Depth
        1. 3.1. Exploring the Simulator UI
          1. 3.1.1. Simulating multi-touch
          2. 3.1.2. Simulating Core Location
          3. 3.1.3. Turning the simulator on its side
          4. 3.1.4. Digging deeper into the simulator filesystem
        2. 3.2. Understanding the Differences between the Simulator and the Real Thing
          1. 3.2.1. Avoiding APIs that won't work on a real device
          2. 3.2.2. Understanding performance differences
        3. 3.3. Summary
    7. II. Building GUIs
      1. 4. Understanding the Basics of an iPhone User Interface
        1. 4.1. Looking at the iPhone Screen
        2. 4.2. Creating a Cinematic User Experience
        3. 4.3. Looking at the Built-in Applications
        4. 4.4. Understanding the Basics of iPhone Navigation
        5. 4.5. Summary
      2. 5. Introducing UIViewController
        1. 5.1. Understanding the Basics of Model, View, Controller
        2. 5.2. Exploring UIViewController
        3. 5.3. Overriding Methods on UIViewController
          1. 5.3.1. Handling view rotations
          2. 5.3.2. Handling memory warnings
        4. 5.4. Working with UIViewController
          1. 5.4.1. Creating the code
          2. 5.4.2. Creating the UIViewController header
          3. 5.4.3. Creating the UIViewController implementation
          4. 5.4.4. Adding the controller to Interface Builder
          5. 5.4.5. Understanding the UIApplicationDelegate
          6. 5.4.6. Creating the model in the App Delegate
          7. 5.4.7. Adding the view to the window
        5. 5.5. Summary
      3. 6. Using UITableView
        1. 6.1. Understanding UITableView Data Sources and Delegates
          1. 6.1.1. Understanding NSIndexPath and how it works with UITableViews
          2. 6.1.2. Exploring UITableViewDataSource
            1. 6.1.2.1. Understanding the core methods in the UITableViewDataSource
            2. 6.1.2.2. Understanding behavioral methods in UITableViewDataSource
          3. 6.1.3. Exploring UITableViewDelegate
            1. 6.1.3.1. Customizing selection behavior
            2. 6.1.3.2. Customizing editing behavior
            3. 6.1.3.3. Handling reordering of rows
        2. 6.2. Adding a UITableView to an Application
          1. 6.2.1. Making a UITableViewDataSource
            1. 6.2.1.1. Writing the UITableViewDataSource implementation
            2. 6.2.1.2. Configuring the UITableView in Interface Builder
          2. 6.2.2. Seeing the basic application run
          3. 6.2.3. Taking action when a row is touched
            1. 6.2.3.1. Making the UITableViewDelegate
              1. 6.2.3.1.1. Allowing the user to select a row
              2. 6.2.3.1.2. Updating the model when the row is touched
            2. 6.2.3.2. Running the application and selecting favorites
        3. 6.3. Configuring a UITableView to Be Grouped
          1. 6.3.1. Adding the state to your model
          2. 6.3.2. Updating your UITableViewDataSource
            1. 6.3.2.1. Getting the group names from your model
            2. 6.3.2.2. Showing the correct value in the cells
            3. 6.3.2.3. Updating the delegate
        4. 6.4. Doing Advanced UITableView Configuration
          1. 6.4.1. Adding an alphabetical list to the side
          2. 6.4.2. Adding search
        5. 6.5. Summary
      4. 7. Working with UITableViewCells
        1. 7.1. Understanding the Parts of a UITableViewCell
        2. 7.2. Adding Images to a UITableViewCell
        3. 7.3. Performing Deeper Customization of UITableViewCells
        4. 7.4. Thinking about Performance in Custom Cells
        5. 7.5. Reusing UITableViewCells
          1. 7.5.1. Understanding the reuse identifier
        6. 7.6. Summary
      5. 8. Working within the UINavigationController Model
        1. 8.1. Understanding the UINavigationController Navigational Model
        2. 8.2. Creating a UINavigationController
        3. 8.3. Configuring a UINavigationController
        4. 8.4. Pushing and Popping UIViewControllers
        5. 8.5. Adding a UIToolbar
        6. 8.6. Allowing Editing of the Rows
          1. 8.6.1. Moving MyView into a UINavigationController
          2. 8.6.2. Making Your EditViewController
          3. 8.6.3. Editing rows
          4. 8.6.4. Adding rows
          5. 8.6.5. Deleting rows
        7. 8.7. Summary
      6. 9. Understanding the UIApplicationDelegate
        1. 9.1. Exploring the Purpose of the UIApplicationDelegate
        2. 9.2. Handling Startup and Shutdown
          1. 9.2.1. Understanding launch methods
          2. 9.2.2. Understanding the applicationWillTerminate method
        3. 9.3. Receiving Notifications while Your Application Is Running
          1. 9.3.1. Handling resource alerts
          2. 9.3.2. Handling phone calls and sleep
          3. 9.3.3. Changing status
          4. 9.3.4. Handling remote notifications
        4. 9.4. Summary
      7. 10. Applying Custom UIViews
        1. 10.1. Understanding Cocoa Touch View Geometry
        2. 10.2. Adding Custom Views to a Project
        3. 10.3. Implementing the Custom View Code
          1. 10.3.1. Working with Core Graphics
            1. 10.3.1.1. Working with basic Core Graphics types
            2. 10.3.1.2. Understanding the core frameworks memory management model
              1. 10.3.1.2.1. Understanding Core Foundation object ownership
              2. 10.3.1.2.2. Using CFRetain and CFRelease
            3. 10.3.1.3. Getting the graphics context
            4. 10.3.1.4. Doing basic drawing operations
            5. 10.3.1.5. Doing transforms
          2. 10.3.2. Implementing drawRect
        4. 10.4. Summary
      8. 11. Handling Touch Events
        1. 11.1. Handling Touch Events in a Custom UIView
          1. 11.1.1. Implementing touchesBegan:withEvent
          2. 11.1.2. Working with the touches NSSet
          3. 11.1.3. Implementing touchesMoved:withEvent:
          4. 11.1.4. Implementing touchesEnded:withEvent:
          5. 11.1.5. Handling multi-touch events
        2. 11.2. Updating Your Custom View with Touch Events
          1. 11.2.1. Moving the circle with a touch
          2. 11.2.2. Adding scaling
        3. 11.3. Summary
      9. 12. Working with Other Controls
        1. 12.1. Finding What Other Controls Are Available in Cocoa Touch
        2. 12.2. Working with a UISlider
          1. 12.2.1. Configuring a UISlider through Interface Builder
          2. 12.2.2. Updating the status of your UISlider
        3. 12.3. Using UITabBar
          1. 12.3.1. Configuring a UITabBar through Interface Builder
          2. 12.3.2. Adding UITabBarItems to a UITabBar
          3. 12.3.3. Doing advanced configuration of UITabBars
          4. 12.3.4. Using UIPickerView
          5. 12.3.5. Configuring UIPickerView through Interface Builder
          6. 12.3.6. Creating the UIPickerViewDataSource
          7. 12.3.7. Creating a UIPickerView delegate
        4. 12.4. Summary
      10. 13. Handling Text Input
        1. 13.1. Configuring the Keyboard through Interface Builder
          1. 13.1.1. Configuring capitalization
          2. 13.1.2. Enabling and disabling auto correction
          3. 13.1.3. Setting the keyboard type
          4. 13.1.4. Setting the behavior of the Return key
          5. 13.1.5. Looking at other settings
        2. 13.2. Working with a Keyboard through Code
          1. 13.2.1. Making the keyboard appear
          2. 13.2.2. Understanding UITextInputTraits
        3. 13.3. Handling Events for the Keyboard
          1. 13.3.1. Creating a UITextFieldDelegate
            1. 13.3.1.1. Knowing when the text changes
            2. 13.3.1.2. Taking action when the user has finished editing
          2. 13.3.2. Moving your view in response to the keyboard appearance
        4. 13.4. Summary
      11. 14. Building Cinematic UIs with Core Animation
        1. 14.1. Using the UIViews Animation Methods
        2. 14.2. Using Advanced Core Animation with CALayer
        3. 14.3. Animating UIImageViews
        4. 14.4. Summary
      12. 15. Using OpenGL ES
        1. 15.1. Understanding the Capabilities of iPhone OpenGL ES
        2. 15.2. Creating a Very Basic OpenGL View
        3. 15.3. Summary
      13. 16. Integrating Safari
        1. 16.1. Opening URLs Using the iPhone Web Browser
        2. 16.2. Using UIWebView
          1. 16.2.1. Adding a UIWebView to your application
          2. 16.2.2. Loading a URL
          3. 16.2.3. Implementing a UIWebViewDelegate
          4. 16.2.4. Loading HTML content from the application bundle
        3. 16.3. Summary
    8. III. Working with Data
      1. 17. Storing User Defaults
        1. 17.1. Acquiring the NSUserDefaults Object
        2. 17.2. Reading and Writing Values to NSUserDefaults
        3. 17.3. Setting Your Default Defaults
        4. 17.4. Using the Settings App
          1. 17.4.1. Adding a settings bundle
          2. 17.4.2. Adding settings to your settings bundle
        5. 17.5. Summary
      2. 18. Implementing a Database with Core Data
        1. 18.1. Understanding Core Data's Building Blocks
        2. 18.2. Adding Core Data Support to Favorite Cities
          1. 18.2.1. Modifying the app delegate
          2. 18.2.2. Working with the Managed Object Model
            1. 18.2.2.1. Designing your schema in Xcode
            2. 18.2.2.2. Defining entities
            3. 18.2.2.3. Defining relationships among entities
            4. 18.2.2.4. Generating classes for entities
            5. 18.2.2.5. Exploring entity properties
        3. 18.3. CRUD — Creating, Reading, Updating, Deleting
          1. 18.3.1. Creating
          2. 18.3.2. Reading
          3. 18.3.3. Updating
          4. 18.3.4. Deleting
          5. 18.3.5. Bringing it together and updating your app
        4. 18.4. Understanding What Core Data Makes Easier
        5. 18.5. Understanding What Core Data Is Not Good For
        6. 18.6. Summary
      3. 19. Connecting to the World with Networking
        1. 19.1. Accessing the Web
          1. 19.1.1. Using URLs with foundational classes
          2. 19.1.2. Using NSURLRequest and NSURLConnection
        2. 19.2. Sending E-mail from within Your App with the Message UI Framework
        3. 19.3. Using Core Foundation Sockets
          1. 19.3.1. Exploring CFSocket
          2. 19.3.2. Getting host info with CFHost
          3. 19.3.3. Using CFStreams
        4. 19.4. Exploring Bonjour
          1. 19.4.1. Browsing for Bonjour services
          2. 19.4.2. Using NSNetServices
        5. 19.5. Summary
      4. 20. Using the Push Notification Service
        1. 20.1. Understanding the Push Notification Service Architecture
          1. 20.1.1. Understanding the push notification communications
            1. 20.1.1.1. Looking at the overall architecture
            2. 20.1.1.2. Examining the push notification message formats
              1. 20.1.1.2.1. Exploring the payload
              2. 20.1.1.2.2. Wrapping the payload in the APNS message
              3. 20.1.1.2.3. Understanding the feedback message
          2. 20.1.2. Understanding push notification security
            1. 20.1.2.1. Understanding connection security
            2. 20.1.2.2. Understanding token security
            3. 20.1.2.3. Acquiring Push Notification Certificates
        2. 20.2. Developing Your Server-Side Push Notification Service
          1. 20.2.1. Implementing a Ruby push notification supplier
          2. 20.2.2. Pushing notifications
          3. 20.2.3. Checking delivery using feedback
        3. 20.3. Integrating Push Notifications with Your iPhone Client
          1. 20.3.1. Registering for notifications
          2. 20.3.2. Receiving notifications in your application
        4. 20.4. Summary
      5. 21. Using the Game Kit API
        1. 21.1. Providing Peer-to-Peer Connectivity
          1. 21.1.1. Finding peers
          2. 21.1.2. Working with sessions
        2. 21.2. Providing In-Game Voice
        3. 21.3. Summary
      6. 22. Implementing Cut, Copy, and Paste
        1. 22.1. Copying and Pasting with Standard Controls
        2. 22.2. Understanding Pasteboard Types
        3. 22.3. Interacting with UIPasteboard
        4. 22.4. Implementing Cut, Copy, and Paste on a Custom View
          1. 22.4.1. Implementing touchesEnded:withEvent: to display the menu
          2. 22.4.2. Implementing the copy: method
          3. 22.4.3. Implementing the paste: method
          4. 22.4.4. Understanding the interactions
        5. 22.5. Summary
      7. 23. Using the Maps API
        1. 23.1. Showing an Embedded Map with MKMapView
          1. 23.1.1. Creating an MKMapView
          2. 23.1.2. Specifying the map region
        2. 23.2. Annotating Maps
          1. 23.2.1. Thinking about performance with annotations
        3. 23.3. Converting Coordinates
        4. 23.4. Summary
    9. IV. Working with Media
      1. 24. Exploring the Supported Media Type
        1. 24.1. Supported Audio Formats
          1. 24.1.1. Compressed audio
          2. 24.1.2. Uncompressed audio
        2. 24.2. Supported Video Formats
        3. 24.3. Summary
      2. 25. Playing Audio
        1. 25.1. Using the AV Foundation Framework
          1. 25.1.1. Setting your audio configuration with AVAudioSession
          2. 25.1.2. Using an AVAudioSessionDelegate
          3. 25.1.3. Playing audio with AVAudioPlayer
          4. 25.1.4. Using an AVAudioPlayerDelegate
        2. 25.2. Playing Audio with OpenAL
        3. 25.3. Summary
      3. 26. Accessing the iPod Librar
        1. 26.1. Working with the Media Player Framework
        2. 26.2. Accessing the Media Library
          1. 26.2.1. Using the MPMediaPickerController
          2. 26.2.2. Searching for media
            1. 26.2.2.1. Understanding media property predicates
            2. 26.2.2.2. Building queries
        3. 26.3. Working with Player Controllers
        4. 26.4. Accessing Media Artwork
        5. 26.5. Summary
      4. 27. Recording Audio
        1. 27.1. Setting up Your AVAudioSession
        2. 27.2. Allocating an AVAudioRecorder
        3. 27.3. Creating a Voice Recorder
        4. 27.4. Summary
      5. 28. Playing Video in Your Application
        1. 28.1. Playing Video Files Contained in the App Bundle
        2. 28.2. Playing Video from the Internet
        3. 28.3. Summary
    10. V. Working with the iPhone Hardware
      1. 29. Discovering Information about the Device
        1. 29.1. Accessing the Battery State
        2. 29.2. Accessing the Proximity Sensor
        3. 29.3. Working with Device Metadata
        4. 29.4. Summary
      2. 30. Getting Your Location Using Core Location
        1. 30.1. Finding Where You Are
          1. 30.1.1. Allocating a CLLocationManager
          2. 30.1.2. Setting yourself as the delegate
          3. 30.1.3. Implementing the CLLocationManagerDelegate protocol
          4. 30.1.4. Starting and stopping location updates
          5. 30.1.5. Viewing your location on Google Maps
        2. 30.2. Narrowing the Accuracy of the Coordinates
        3. 30.3. Filtering Location Updates
        4. 30.4. Looking at the Final Code
        5. 30.5. Working with the iPhone 3GS Compass
        6. 30.6. Summary
      3. 31. Working with the Accelerometer
        1. 31.1. Determining Which Way Is Up
          1. 31.1.1. Building a bubble level
            1. 31.1.1.1. Accessing the UIAccelerometer in viewDidLoad
            2. 31.1.1.2. Implementing the UIAccelerometerDelegate method
            3. 31.1.1.3. Adding a low-pass filter
          2. 31.1.2. Understanding the UIAcceleration object
        2. 31.2. Capturing Shake Events
          1. 31.2.1. Building a "shake to break" detector
          2. 31.2.2. Implementing drawRect
          3. 31.2.3. Implementing motionBegan and motionEnded
          4. 31.2.4. Cancellation of motion events
        3. 31.3. Summary
      4. 32. Interfacing with Peripherals
        1. 32.1. Creating Accessories That Interface with iPhone
        2. 32.2. Finding Accessories That Are Connected Using EAAccessoryManager
        3. 32.3. Understanding the EAAccessory Class
        4. 32.4. Working with EASession
        5. 32.5. Talking to Your Device Using NSStreams
        6. 32.6. Summary
    11. VI. Handling Distribution
      1. 33. Code Signing Your Apps
        1. 33.1. Acquiring a Development Certificate
        2. 33.2. Understanding the Provisioning Process
          1. 33.2.1. Understanding development, distribution, and ad hoc
          2. 33.2.2. Installing provisioning profiles
          3. 33.2.3. Exploring what happens when an app is signed
          4. 33.2.4. Setting up your build to be signed
        3. 33.3. Doing Ad Hoc Builds
          1. 33.3.1. Configuring the build in Xcode
          2. 33.3.2. Distributing to users
        4. 33.4. Summary
      2. 34. Expanding Your Application Using the In-App Purchase Support
        1. 34.1. Knowing the Types of Things You Can Sell
        2. 34.2. Working with Unlockable Content
        3. 34.3. Setting up Purchasable Content in iTunes Connect
        4. 34.4. Working with Store Kit
          1. 34.4.1. Verifying app purchase availability
          2. 34.4.2. Presenting your store
          3. 34.4.3. Making the purchase
          4. 34.4.4. Processing the payment
          5. 34.4.5. Verifying the transaction
          6. 34.4.6. Unlocking the content
          7. 34.4.7. Restoring purchased content
          8. 34.4.8. Understanding In-App Purchasing testing
        5. 34.5. Summary

    Product information

    • Title: Cocoa Touch™ for iPhone® OS 3
    • Author(s): Jiva DeVoe
    • Release date: November 2009
    • Publisher(s): Wiley
    • ISBN: 9780470481073