You are previewing Beginning iOS 4 Application Development.
O'Reilly logo
Beginning iOS 4 Application Development

Book Description

The ideal starting point for creating apps using iOS 4

Written by an experienced Apple developer and trainer, this full-color reference serves as an ideal jumping point for creating applications for Apple's iOS 4 that runs on the iPhone, iPod Touch, and iPad. In addition to in-depth coverage of the iOS SDK, the book walks you through the various core aspects of iPhone and iPad development. You'll learn how to take advantage of the tools provided by XCode and you'll benefit from a solid introduction to Objective-C, which allows you to have a smooth transition to iPhone development from another platform.

  • Offers a solid foundation for creating applications for Apple's iOS 4

  • Covers all the new features of iOS 4 and provides a new applications template for developing iPad and iPhone apps

  • Addresses the new PopoverView for iPad apps

  • Shows how to develop background applications, which is one of the new features in iOS 4

Beginning iOS 4 Application Development is your ultimate resource for creating applications for Apple's iOS 4.

Table of Contents

  1. Copyright
  2. Credits
  3. About the Author
  4. About the Technical Editor
  5. Acknowledgments
  6. Introduction
    1. Who This Book Is For
    2. What This Book Covers
    3. How This Book Is Structured
    4. What You Need to Use This Book
    5. Conventions
    6. Source Code and Answers Appendix
    7. Errata
    8. p2p.wrox.com
  7. I. Getting Started
    1. 1. Getting Started with iOS 4 Programming
      1. 1.1. Obtaining the iPhone SDK
      2. 1.2. Components of the iPhone SDK
        1. 1.2.1. Xcode
        2. 1.2.2. iPhone Simulator
          1. 1.2.2.1. Features of the iPhone Simulator
          2. 1.2.2.2. Uninstalling Applications from the iPhone Simulator
        3. 1.2.3. Interface Builder
        4. 1.2.4. Instruments
      3. 1.3. Architecture of the iPhone OS
      4. 1.4. Some Useful Information before You Get Started
        1. 1.4.1. Versions of the iPhone OS
        2. 1.4.2. Testing on Real Devices
        3. 1.4.3. Screen Resolutions
      5. 1.5. Summary
    2. 2. Write Your First Hello World! Application
      1. 2.1. Getting Started with Xcode
        1. 2.1.1. Using Interface Builder
        2. 2.1.2. Writing Some Code
      2. 2.2. Customizing Your Application Icon
      3. 2.3. Displaying a Splash Screen
      4. 2.4. Summary
    3. 3. Views, Outlets, and Actions
      1. 3.1. Outlets and Actions
      2. 3.2. Using Views
        1. 3.2.1. Using the Alert View
        2. 3.2.2. Using the Action Sheet
        3. 3.2.3. Page Control and Image View
        4. 3.2.4. Using the Web View
      3. 3.3. Adding Views Dynamically Using Code
      4. 3.4. Understanding View Hierarchy
      5. 3.5. Summary
    4. 4. View Controllers
      1. 4.1. The View-Based Application Template
        1. 4.1.1. Editing XIB Files
          1. 4.1.1.1. Application Delegate
          2. 4.1.1.2. Controlling Your UI Using View Controllers
      2. 4.2. The Window-Based Application Template
        1. 4.2.1. Adding a View Controller and Views Programmatically
        2. 4.2.2. Creating and Connecting Actions
        3. 4.2.3. Switching to Another View
        4. 4.2.4. Animating the Switching of Views
      3. 4.3. The Split View-Based Application Template
        1. 4.3.1. Displaying Some Items in the Split View-Based Application
      4. 4.4. The Tab Bar Application Template
      5. 4.5. Summary
    5. 5. Multi-Platform Support for the iPhone and iPad
      1. 5.1. Technique 1 — Modifying the Device Target Setting
        1. 5.1.1. Detecting the Platform Programmatically
      2. 5.2. Technique 2 — Creating Universal Applications
      3. 5.3. Technique 3 — Maintaining Two Code Bases
      4. 5.4. Making Your Choice
      5. 5.5. Summary
    6. 6. Keyboard Inputs
      1. 6.1. Using the Keyboard
      2. 6.2. Customizing the Type of Inputs
        1. 6.2.1. Making the Keyboard Go Away
        2. 6.2.2. Automatically Displaying the Keyboard When the View Is Loaded
      3. 6.3. Detecting the Presence of the Keyboard
        1. 6.3.1. Using the Scroll View
        2. 6.3.2. Scrolling Views When the Keyboard Appears
      4. 6.4. Summary
    7. 7. Screen Rotations
      1. 7.1. Responding to Device Rotations
        1. 7.1.1. Different Types of Screen Orientations
        2. 7.1.2. Handling Rotations
          1. 7.1.2.1. willAnimateFirstHalfOfRotationToInterfaceOrientation:
          2. 7.1.2.2. willAnimateSecondHalfOfRotationFromInterfaceOrientation:
          3. 7.1.2.3. willRotateToInterfaceOrientation:
          4. 7.1.2.4. willAnimateRotationToInterfaceOrientation:
      2. 7.2. Programmatically Rotating the Screen
        1. 7.2.1. Rotating During Runtime
        2. 7.2.2. Displaying the View Window in a Specific Orientation When Loading
      3. 7.3. Summary
  8. II. Displaying and Persisting Data
    1. 8. Using the Table View
      1. 8.1. A Simple Table View
        1. 8.1.1. Adding a Header and Footer
        2. 8.1.2. Adding an Image
        3. 8.1.3. Displaying the Item Selected
        4. 8.1.4. Indenting
        5. 8.1.5. Modifying the Height of Each Row
      2. 8.2. Using the Table View in a Navigation-Based Application
      3. 8.3. Displaying Sections
        1. 8.3.1. Adding Indexing
        2. 8.3.2. Adding Search Capability
        3. 8.3.3. Disclosures and Check Marks
        4. 8.3.4. Navigating to Another View
      4. 8.4. Summary
    2. 9. Application Preferences
      1. 9.1. Creating Application Preferences
      2. 9.2. Programmatically Accessing the Settings Values
        1. 9.2.1. Loading the Settings Values
        2. 9.2.2. Resetting the Preferences Settings Values
        3. 9.2.3. Saving the Settings Values
      3. 9.3. Summary
    3. 10. File Handling
      1. 10.1. Understanding the Application Folders
        1. 10.1.1. Using the Documents and Library Folders
        2. 10.1.2. Storing Files in the Temporary Folder
      2. 10.2. Using Property Lists
      3. 10.3. Copying Bundled Resources
      4. 10.4. Summary
    4. 11. Database Storage Using SQLite3
      1. 11.1. Using SQLite3
      2. 11.2. Creating and Opening a Database
        1. 11.2.1. Examining the Database Created
        2. 11.2.2. Creating a Table
        3. 11.2.3. Inserting Records
        4. 11.2.4. Bind Variables
        5. 11.2.5. Retrieving Records
      3. 11.3. Bundling SQLite Databases with Your Application
      4. 11.4. Summary
  9. III. Advanced iOS 4 Programming Techniques
    1. 12. Simple Animations and Video Playback
      1. 12.1. Using the NSTimer Class
        1. 12.1.1. Animating the Visual Change
      2. 12.2. Transforming Views
        1. 12.2.1. Translation
        2. 12.2.2. Rotation
        3. 12.2.3. Scaling
      3. 12.3. Animating a Series of Images
      4. 12.4. Playing Video on the iPhone
      5. 12.5. Summary
    2. 13. Accessing Built-In Applications
      1. 13.1. Sending E-Mails
        1. 13.1.1. Invoking Safari
        2. 13.1.2. Invoking the Phone
        3. 13.1.3. Invoking SMS
      2. 13.2. Accessing the Camera and the Photo Library
        1. 13.2.1. Accessing the Photo Library
        2. 13.2.2. Accessing the Camera
      3. 13.3. Summary
    3. 14. Recognizing Gestures
      1. 14.1. Recognizing Gestures
        1. 14.1.1. Tapping
        2. 14.1.2. Pinching
        3. 14.1.3. Rotation
        4. 14.1.4. Panning (or Dragging)
        5. 14.1.5. Swiping
        6. 14.1.6. Long Press
      2. 14.2. Detecting Touches
        1. 14.2.1. Detecting Single Touch
        2. 14.2.2. Detecting Multi-Touches
        3. 14.2.3. Implementing the Pinch Gesture
        4. 14.2.4. Implementing the Drag Gesture
      3. 14.3. Summary
    4. 15. Accessing the Accelerometer
      1. 15.1. Using the Accelerometer
      2. 15.2. Visualizing the Accelerometer Data
      3. 15.3. Using the Shake API to Detect Shakes
        1. 15.3.1. Performing an Action When the Device Is Shaken
      4. 15.4. Summary
  10. IV. Network Programming Techniques
    1. 16. Web Services
      1. 16.1. Basics of Consuming XML Web Services
        1. 16.1.1. Using SOAP 1.1
        2. 16.1.2. Using SOAP 1.2
      2. 16.2. Consuming a Web Service in Your iPhone Application
      3. 16.3. Parsing the XML Response
      4. 16.4. Summary
    2. 17. Bluetooth Programming
      1. 17.1. Using the Game Kit Framework
        1. 17.1.1. Searching for Peer Devices
        2. 17.1.2. Sending and Receiving Data
      2. 17.2. Implementing Voice Chatting
      3. 17.3. Summary
    3. 18. Bonjour Programming
      1. 18.1. Creating the Application
      2. 18.2. Publishing a Service
      3. 18.3. Browsing for Services
      4. 18.4. Summary
    4. 19. Apple Push Notification Service
      1. 19.1. Generating a Certificate Request
      2. 19.2. Generating a Development Certificate
      3. 19.3. Creating an Application ID
        1. 19.3.1. Configuring an App ID for Push Notifications
        2. 19.3.2. Creating a Provisioning Profile
        3. 19.3.3. Provisioning a Device
      4. 19.4. Creating the iPhone Application
      5. 19.5. Creating the Push Notification Provider
      6. 19.6. Summary
    5. 20. Displaying Maps
      1. 20.1. Displaying Maps and Monitoring Changes Using the Map Kit
      2. 20.2. Getting Location Data
        1. 20.2.1. Displaying Location Using a Map
        2. 20.2.2. Getting Directional Information
        3. 20.2.3. Rotating the Map
        4. 20.2.4. Displaying Annotations
        5. 20.2.5. Reverse Geocoding
        6. 20.2.6. Displaying a Disclosure Button
      3. 20.3. Summary
    6. 21. Background Applications
      1. 21.1. Understanding Background Execution on the iPhone
        1. 21.1.1. Examining the Different Application States
        2. 21.1.2. Opting Out of Background Mode
        3. 21.1.3. Detecting Multi-Tasking Support
        4. 21.1.4. Tracking Locations in the Background
        5. 21.1.5. Making Your Location Apps More Energy Efficient
      2. 21.2. Local Notification
      3. 21.3. Summary
  11. V. Appendices
    1. A. Testing on an Actual Device
      1. A.1. Signing Up for the iPhone Developer Program
      2. A.2. Obtaining the UDID of Your Device
      3. A.3. Logging in to the iPhone Provisioning Portal
      4. A.4. Generating a Certificate
      5. A.5. Registering Your Devices
      6. A.6. Creating an Application ID
      7. A.7. Creating a Provisioning Profile
      8. A.8. Understanding Application ID and the Wildcard
      9. A.9. Preparing for App Store Submission
      10. A.10. Summary
    2. B. Getting Around in Xcode
      1. B.1. Launching Xcode
        1. B.1.1. Project Types Supported
        2. B.1.2. Customizing the Toolbar
        3. B.1.3. Code Sense
        4. B.1.4. Running the Application
      2. B.2. Debugging Your Applications
        1. B.2.1. Errors
        2. B.2.2. Warnings
        3. B.2.3. Setting Breakpoints
        4. B.2.4. Using NSLog
        5. B.2.5. Documentation
    3. C. Getting Around in Interface Builder
      1. C.1. .xib Window
      2. C.2. Designing the View
      3. C.3. Inspector Window
        1. C.3.1. Attributes Inspector Window
        2. C.3.2. Connections Inspector Window
        3. C.3.3. Size Inspector Window
        4. C.3.4. Identity Inspector Window
      4. C.4. Library
      5. C.5. Outlets and Actions
        1. C.5.1. Creating Outlets and Actions
        2. C.5.2. Connecting Outlets and Actions
          1. C.5.2.1. Method 1
          2. C.5.2.2. Method 2
    4. D. Crash Course in Objective-C
      1. D.1. Directives
      2. D.2. Classes
        1. D.2.1. @interface
        2. D.2.2. @implementation
        3. D.2.3. @class
        4. D.2.4. Class Instantiation
        5. D.2.5. Fields
        6. D.2.6. Access Privileges
        7. D.2.7. Methods
        8. D.2.8. Message Sending (Calling Methods)
        9. D.2.9. Properties
        10. D.2.10. Initializers
      3. D.3. Memory Management
        1. D.3.1. Reference Counting
          1. D.3.1.1. alloc
          2. D.3.1.2. new
          3. D.3.1.3. retain
          4. D.3.1.4. release
          5. D.3.1.5. Convenience Method and Autorelease
          6. D.3.1.6. Autorelease Pools
          7. D.3.1.7. dealloc
          8. D.3.1.8. Memory Management Tips
      4. D.4. Protocols
        1. D.4.1. Delegate
      5. D.5. Selectors
      6. D.6. Categories