iPAD iOS 5 development essentials

Neil Smyth

The aim of iPad iOS 5 Development essentials is to teach you the skills necessary to build your own applications for the iPad.

Beginning with the basics, this book provideds an overview of the iPad hardware and the architecture of iOS 5.

An introduction to programming in Objective-C is provided followed by an in-depth look at the design of iPad applications and user interfaces.

More advaced topics such as file handling, user interface layout and resizing, database management, graphics drawing and animation are also covered, as are touch screen handling, gesture reognition, multitasking, iAds integration, map and location management, split views, camera access and video playback support.

New iOS 5 specific features are also covered in detail including page view controller implementation, the UIDocument class, iCloud based storage, Storyboard user interface design, automatic reference filtering with Core Image.

iPad iOS 5 Development essentials take a modular approach to the subject of iPad application development with each chapter covering a self contained topic area. This makes the book both an esay to follow learning aid and an excellent reference resource.

Table of Contents
    Introduction to iPad iOS 5 Development Essentials
        Example Source Code
    The History of iOS
    The Anatomy of a New iPad
  •         Display
  •         Wireless Connectivity
  •         Wired Connectivity
  •         Memory
  •         Cameras
  •         Sensors
  •         Location Detection
  •         Central Processing Unit (CPU)
  •         Speaker and Microphone
  •         Battery
    iOS 5 Architecture and SDK Frameworks
  •         iPhone OS becomes iOS
  •         An Overview of the iOS 5 Architecture
  •         The Cocoa Touch Layer
  •         The iOS Media Layer
  •         iOS Audio Support
  •         The iOS Core Services Layer
  •         The iOS Core OS Layer
    Joining the Apple iOS 5 Developer Program
  •         Registered Apple Developer
  •         iOS Developer Program
  •         When to Enroll in the iOS Developer Program?
  •         Enrolling in the iOS Developer Program
    Installing Xcode 4 and the iOS 5 SDK (iPad)
  •         Identifying if you have an Intel or PowerPC based Mac
  •         Installing Xcode 4 and the iOS 5 SDK
  •         Starting Xcode 4
    Creating a Simple iPad iOS 5 App
  •         Starting Xcode 4
  •         Creating the iOS App User Interface
  •         Changing Component Properties
  •         Adding Objects to the User Interface
  •         Building and Running an iOS App in Xcode 4
  •         Dealing with Build Errors
    Testing iOS 5 Apps on the iPad ? Developer Certificates and Provisioning Profiles
  •         Creating an iOS Development Certificate Signing Request
  •         Submitting the iOS Development Certificate Signing Request
  •         Installing an iOS Development Certificate
  •         Assigning Devices
  •         Creating an App ID
  •         Creating an iOS Development Provisioning Profile
  •         Enabling an iPad Device for Development
  •         Associating an App ID with an App
  •         iOS and SDK Version Compatibility
  •         Installing an App onto a Device
    The Basics of Objective-C Programming
  •         Objective-C Data Types and Variables
  •         Objective-C Expressions
  •         Objective-C Flow Control with if and else
  •         Looping with the for Statement
  •         Objective-C Looping with do and while
  •         Objective-C do ... while loops
    The Basics of Object Oriented Programming in Objective-C
  •         What is an Object?
  •         What is a Class?
  •         Declaring an Objective-C Class Interface
  •         Adding Instance Variables to a Class
  •         Define Class Methods
  •         Declaring an Objective-C Class Implementation
  •         Declaring and Initializing a Class Instance
  •         Automatic Reference Counting (ARC)
  •         Calling Methods and Accessing Instance Data
  •         Objective-C and Dot Notation
  •         How Variables are Stored
  •         An Overview of Indirection
  •         Indirection and Objects
  •         Indirection and Object Copying
  •         Creating the Program Section
  •         Bringing it all Together
  •         Structuring Object-Oriented Objective-C Code
    An Overview of the iPad iOS 5 Application Development Architecture
  •         Model View Controller (MVC)
  •         The Target-Action pattern, IBOutlets and IBActions
  •         Subclassing
  •         Delegation
    Creating an Interactive iOS 5 iPad App
  •         Creating the New Project
  •         Creating the User Interface
  •         Building and Running the Sample Application
  •         Adding Actions and Outlets
  •         Connecting the Actions and Outlets to the User Interface
  •         Building and Running the Finished Application
    Writing iOS 5 Code to Hide the iPad Keyboard
  •         Creating the Example Application
  •         Hiding the Keyboard when the User Touches the Return Key
  •         Hiding the Keyboard when the User Taps the Background
    Establishing Outlets and Actions using the Xcode Assistant Editor
  •         Displaying the Assistant Editor
  •         Using the Assistant Editor
  •         Adding an Outlet using the Assistant Editor
  •         Adding an Action using the Assistant Editor
    Understanding iPad iOS 5 Views, Windows and the View Hierarchy
  •         Creating the Storyboard Example Project
  •         Accessing the Storyboard
  •         Adding Scenes to the Storyboard
  •         Configuring Storyboard Segues
  •         Configuring Storyboard Transitions
  •         Associating a View Controller with a Scene
  •         Solving the Blank View Problem
  •         Triggering a Storyboard Segue Programmatically
  •         Performing Tasks before a Segue
    Using Xcode Storyboarding with iOS 5
  •         Creating the Storyboard Example Project
  •         Accessing the Storyboard
  •         Adding Scenes to the Storyboard
  •         Configuring Storyboard Segues
  •         Configuring Storyboard Transitions
  •         Associating a View Controller with a Scene
  •         Solving the Blank View Problem
  •         Triggering a Storyboard Segue Programmatically
  •         Performing Tasks before a Segue
    Using Xcode Storyboards to create an iOS 5 iPad Tab Bar Application
  •         An Overview of the Tab Bar
  •         Understanding View Controllers in a Multiview Application
  •         Setting up the Tab Bar Example Application
  •         Reviewing the Project Files
  •         Renaming the Initial View Controller
  •         Adding the View Controller for the Second Content View
  •         Adding the Tab Bar Controller to the Storyboard
  •         Adding a Second View Controller to the Storyboard
  •         Designing the View Controller User interfaces
  •         Configuring the Tab Bar Items
  •         Building and Running the Application
    An Overview of iPad iOS 5 Table Views and Xcode Storyboards
  •         An Overview of the Table View
  •         Static vs. Dynamic Table Views
  •         The Table View Delegate and dataSource
  •         Table View Styles
  •         Table View Cell Styles
    Using Xcode Storyboards to Build Dynamic iPad TableViews with Prototype Table View Cells
  •         Creating the Example Project
  •         Adding the TableView Controller to the Storyboard
  •         Creating the UITableViewController and UITableViewCell Subclasses
  •         Declaring the Cell Reuse Identifier
  •         Designing a Storyboard UITableView Prototype Cell
  •         Modifying the CarTableViewCell Class
  •         Creating the Table View Datasource
  •         Downloading and Adding the Image Files
  •         Compiling and Running the Application
    Implementing iPad TableView Navigation using Xcode Storyboards
  •         Understanding the Navigation Controller
  •         Adding the New Scene to the Storyboard
  •         Adding a Navigation Controller
  •         Establishing the Storyboard Segue
  •         Modifying the CarDetailViewController Class
  •         Using prepareForSegue: to Pass Data between Storyboard Scenes
  •         Testing the Application
    Using an Xcode Storyboard to Create a Static iPad Table View
  •         An Overview of the Static Table Project
  •         Creating the Project
  •         Adding a Table View Controller
  •         Changing the Table View Content Type
  •         Designing the Static Table
  •         Adding Items to the Table Cells
  •         Modifying the StaticTableViewController Class
  •         Building and Running the Application
    Creating a Simple iOS 5 iPad Table View Application
  •         Setting up the Project
  •         Adding the Table View Component
  •         Making the Delegate and dataSource Connections
  •         Implementing the dataSource
  •         Building and Running the Application
  •         Adding Table View Images and Changing Cell Styles
    Creating a Navigation based iOS 5 iPad Application using TableViews
  •         Understanding the Navigation Controller
  •         An Overview of the Example
  •         Setting up the Project
  •         Reviewing the Project Files
  •         Adding the Root View Controller
  •         Creating the Navigation Controller
  •         Setting up the Data in the Root View Controller
  •         Writing Code to Display the Data in the Table View
  •         Creating the Second View Controller
  •         Connecting the Second View Controller to the Root View Controller
  •         Implementing the Functionality of the Second View Controller
  •         Adding the Navigation Code
  •         Controlling the Navigation Controller Stack Programmatically
    An iPad iOS 5 Split View and Popover Example
  •         An Overview of Split View and Popovers
  •         About the Example iPad Split View and Popover Project
  •         Creating the Project
  •         Reviewing the Project
  •         Reviewing the Application Delegate Class
  •         Configuring Master View Items
  •         Configuring the Detail View Controller
  •         Connecting Master Selections to the Detail View
  •         Popover Implementation
  •         Testing the Application
    Implementing a Page based iOS 5 iPad Application using UIPageViewController
  •         The UIPageViewController Class
  •         The UIPageViewController DataSource
  •         Navigation Orientation
  •         Spine Location
  •         The UIPageViewController Delegate Protocol
    An Example iOS 5 iPad UIPageViewController Application
  •         The Xcode Page-based Application Template
  •         Creating the Project
  •         Adding the Content View Controller
  •         Creating Data Model
  •         Initializing the UIPageViewController
  •         Running the UIPageViewController Application
    Using the UIPickerView and UIDatePicker Components in iOS 5 iPad Applications
  •         The DatePicker and PickerView Components
  •         A DatePicker Example
  •         Designing the User Interface
  •         Coding the Date Picker Example Functionality
  •         Modifying viewDidUnload
  •         Building and Running the iPad Date Picker Application
    An iOS 5 iPad UIPickerView Example
  •         Creating the iPad PickerView Project
  •         UIPickerView Delegate and DataSource
  •         The pickerViewController.h File
  •         Designing the User Interface
  •         Initializing the Arrays
  •         Implementing the DataSource Protocol
  •         Implementing the Delegate
  •         Updating viewDidUnload
  •         Testing the Application
    Working with Directories on iOS 5
  •         The Application Documents Directory
  •         The Objective-C NSFileManager, NSFileHandle and NSData Classes
  •         Understanding Pathnames in Objective-C
  •         Creating an NSFileManager Instance Object
  •         Identifying the Current Working Directory
  •         Identifying the Documents Directory
  •         Identifying the Temporary Directory
  •         Changing Directory
  •         Creating a New Directory
  •         Deleting a Directory
  •         Listing the Contents of a Directory
  •         Getting the Attributes of a File or Directory
    Working with iPad Files on iOS 5
  •         Creating an NSFileManager Instance
  •         Checking for the Existence of a File
  •         Comparing the Contents of Two Files
  •         Checking if a File is Readable/Writable/Executable/Deletable
  •         Moving/Renaming a File
  •         Copying a File
  •         Removing a File
  •         Creating a Symbolic Link
  •         Reading and Writing Files with NSFileManager
  •         Working with Files using the NSFileHandle Class
  •         Creating an NSFileHandle Object
  •         NSFileHandle File Offsets and Seeking
  •         Reading Data from a File
  •         Writing Data to a File
  •         Truncating a File
    iOS 5 iPad Directory Handling and File I/O ? A Worked Example
  •         The Example iPad Application
  •         Setting up the Application Project
  •         Defining the Actions and Outlets
  •         Designing the User Interface
  •         Checking the Data File on Application Startup
  •         Implementing the Action Method
  •         Building and Running the Example
    Preparing an iOS 5 App to use iCloud Storage
  •         What is iCloud?
  •         iCloud Data Storage Services
  •         Preparing an Application to Use iCloud Storage
  •         Creating an iOS 5 iCloud enabled App ID
  •         Creating and Installing an iCloud Enabled Provisioning Profile
  •         Creating an iCloud Entitlements File
  •         Manually Creating the Entitlements File
  •         Accessing Multiple Ubiquity Containers
  •         Ubiquity Container URLs
    Managing Files using the iOS 5 UIDocument Class
  •         An Overview of the UIDocument Class
  •         Subclassing the UIDocument Class
  •         Conflict Resolution and Document States
  •         The UIDocument Example Application
  •         Creating a UIDocument Subclass
  •         Declaring the Outlets and Actions
  •         Designing the User Interface
  •         Implementing the Application Data Structure
  •         Implementing the contentsForType Method
  •         Implementing the loadFromContents Method
  •         Loading the Document at App Launch
  •         Saving Content to the Document
  •         Testing the Application
    Using iCloud Storage in an iOS 5 iPad Application
  •         iCloud Usage Guidelines
  •         Preparing the iCloudStore Application for iCloud Access
  •         Configuring the View Controller
  •         Implementing the viewDidLoad Method
  •         Implementing the metadataQueryDidFinishGathering: Method
  •         Implementing the saveDocument Method
  •         Enabling iCloud Document and Data Storage on an iPad
  •         Running the iCloud Application
  •         Reviewing and Deleting iCloud Based Documents
  •         Making a Local File Ubiquitous
    Synchronizing iPad iOS 5 Key-Value Data using iCloud
  •         An Overview of iCloud Key-Value Data Storage
  •         Sharing Data Between Applications
  •         Data Storage Restriction
  •         Conflict Resolution
  •         Receiving Notification of Key-Value Changes
  •         An iCloud Key-Value Data Storage Example
  •         Enabling the Application for iCloud Key Value Data Storage
  •         Implementing the View Controller
  •         Modifying the viewDidLoad Method
  •         Implementing the Notification Method
  •         Implementing the saveData Method
  •         Designing the User Interface
  •         Testing the Application
    iOS 5 iPad Data Persistence using Archiving
  •         An Overview of Archiving
  •         The Archiving Example Application
  •         Implementing the Actions and Outlets
  •         Memory Management
  •         Designing the User Interface
  •         Checking for the Existence of the Archive File on Startup
  •         Archiving Object Data in the Action Method
  •         Testing the Application
    iOS 5 iPad Database Implementation using SQLite
  •         What is SQLite?
  •         Structured Query Language (SQL)
  •         Trying SQLite on MacOS X
  •         Preparing an iPad Application Project for SQLite Integration
  •         Key SQLite Functions
  •         Declaring a SQLite Database
  •         Opening or Creating a Database
  •         Preparing and Executing a SQL Statement
  •         Creating a Database Table
  •         Extracting Data from a Database Table
  •         Closing a SQLite Database
    An Example SQLite based iOS 5 iPad Application
  •         About the Example SQLite iPad Application
  •         Creating and Preparing the SQLite Application Project
  •         Importing sqlite3.h and declaring the Database Reference
  •         Creating the Outlets and Actions
  •         Updating viewDidUnload
  •         Creating the Database and Table
  •         Implementing the Code to Save Data to the SQLite Database
  •         Implementing Code to Extract Data from the SQLite Database
  •         Designing the User Interface
  •         Building and Running the Application
    Working with iOS 5 iPad Databases using Core Data
  •         The Core Data Stack
  •         Managed Objects
  •         Managed Object Context
  •         Managed Object Model
  •         Persistent Store Coordinator
  •         Persistent Object Store
  •         Defining an Entity Description
  •         Obtaining the Managed Object Context
  •         Getting an Entity Description
  •         Creating a Managed Object
  •         Getting and Setting the Attributes of a Managed Object
  •         Fetching Managed Objects
  •         Retrieving Managed Objects based on Criteria
    An iOS 5 iPad Core Data Tutorial
  •         The iPad Core Data Example Application
  •         Creating a Core Data based iPad Application
  •         Creating the Entity Description
  •         Adding a View Controller
  •         Adding Actions and Outlets to the View Controller
  •         Designing the User Interface
  •         Saving Data to the Persistent Store using Core Data
  •         Retrieving Data from the Persistent Store using Core Data
  •         Updating viewDidUnload
  •         Building and Running the Example Application
    An Overview of iOS 5 iPad Multitouch, Taps and Gestures
  •         The Responder Chain
  •         Forwarding an Event to the Next Responder
  •         Gestures
  •         Taps
  •         Touches
  •         Touch Notification Methods
  •         touchesBegan method
  •         touchesMoved method
  •         touchesEnded method
  •         touchesCancelled method
    An Example iOS 5 iPad Touch, Multitouch and Tap Application
  •         The Example iOS 5 iPad Tap and Touch Application
  •         Creating the Example iOS Touch Project
  •         Creating the Outlets
  •         Designing the User Interface
  •         Enabling Multitouch on the View
  •         Implementing the touchesBegan Method
  •         Implementing the touchesMoved Method
  •         Implementing the touchesEnded Method
  •         Getting the Coordinates of a Touch
  •         Building and Running the Touch Example Application
    Detecting iOS 5 iPad Touch Screen Gesture Motions
  •         The Example iOS 5 iPad Gesture Application
  •         Creating the Example Project
  •         Creating Outlets
  •         Designing the Application User Interface
  •         Implementing the touchesBegan Method
  •         Implementing the touchesMoved Method
  •         Implementing the touchesEnded Method
  •         Building and Running the iPad Gesture Example
    Identifying iPad Gestures using iOS 5 Gesture Recognizers
  •         The UIGestureRecognizer Class
  •         Recognizer Action Messages
  •         Discrete and Continuous Gestures
  •         Obtaining Data from a Gesture
  •         Recognizing Tap Gestures
  •         Recognizing Pinch Gestures
  •         Detecting Rotation Gestures
  •         Recognizing Pan and Dragging Gestures
  •         Recognizing Swipe Gestures
  •         Recognizing Long Touch (Touch and Hold) Gestures
    An iPad iOS 5 Gesture Recognition Tutorial
  •         Creating the Gesture Recognition Project
  •         Configuring the Interface File
  •         Designing the User Interface
  •         Adding the Action Methods
  •         Testing the Gesture Recognition Application
    An iOS 5 iPad Graphics Tutorial using Quartz 2D and Core Image
  •         The iOS iPad Drawing Example Application
  •         Creating the New Project
  •         Creating the UIView Subclass
  •         Locating the drawRect Method in the UIView Subclass
  •         Drawing a Line
  •         Drawing Paths
  •         Drawing a Rectangle
  •         Drawing an Ellipse or Circle
  •         Filling a Path with a Color
  •         Drawing an Arc
  •         Drawing a Cubic Bézier Curve
  •         Drawing a Quadratic Bézier Curve
  •         Dashed Line Drawing
  •         Drawing an Image into a Graphics Context
  •         Image Filtering with the Core Image Framework
    Basic iOS 5 iPad Animation using Core Animation
  •         UIView Core Animation Blocks
  •         Understanding Animation Curves
  •         Receiving Notification of Animation Completion
  •         Performing Affine Transformations
  •         Combining Transformations
  •         Creating the Animation Example Application
  •         Implementing the Interface File
  •         Drawing in the UIView
  •         Detecting Screen Touches and Performing the Animation
  •         Building and Running the Animation Application
    Integrating iAds into an iOS 5 iPad App
  •         iOS iPad Advertising Options
  •         iAds Advertisement Formats
  •         Basic Rules for the Display of iAds
  •         Creating an Example iAds iPad Application
  •         Adding the iAds Framework to the Xcode Project
  •         Configuring the View Controller
  •         Designing the User Interface
  •         Creating the Banner Ad
  •         Displaying the Ad
  •         Changing Ad Format during Device Rotation
  •         Implementing the Delegate Methods
  •         bannerViewActionShouldBegin
  •         bannerViewActionDidFinish
  •         bannerView:didFailToReceiveAdWithError
  •         bannerViewWillLoadAd
    An Overview of iOS 5 iPad Multitasking
  •         Understanding iOS Application States
  •         A Brief Overview of the Multitasking Application Lifecycle
  •         Disabling Multitasking for an iOS Application
  •         Checking for Multitasking Support
  •         Supported Forms of Background Execution
  •         The Rules of Background Execution
  •         Scheduling Local Notifications
    Scheduling iOS 5 iPad Local Notifications
  •         Creating the Local Notification iPad App Project
  •         Locating the Application Delegate Method
  •         Adding a Sound File to the Project
  •         Scheduling the Local Notification
  •         Testing the Application
  •         Cancelling Scheduled Notifications
  •         Immediate Triggering of a Local Notification
    Getting iPad Location Information using the iOS 5 Core Location Framework
  •         The Basics of Core Location
  •         Configuring the Desired Location Accuracy
  •         Configuring the Distance Filter
  •         The Location Manager Delegate
  •         Obtaining Location Information from CLLocation Objects
  •         Longitude and Latitude
  •         Accuracy
  •         Altitude
  •         Calculating Distances
  •         Location Information and Multitasking
    An Example iOS 5 iPad Location Application
  •         Creating the Example iOS 5 iPad Location Project
  •         Adding the Core Location Framework to the Project
  •         Configuring the View Controller
  •         Designing the User Interface
  •         Creating the CLLocationManager Object
  •         Implementing the Action Method
  •         Implementing the Application Delegate Methods
  •         Updating viewDidUnload
  •         Building and Running the iPad Location Application
    Working with Maps on the iPad with MapKit and the MKMapView Class (iOS 5)
  •         About the MapKit Framework
  •         Understanding Map Regions
  •         About the iPad MKMapView Tutorial
  •         Creating the iPad Map Tutorial
  •         Adding the MapKit Framework to the Xcode Project
  •         Declaring an Outlet for the MapView
  •         Creating the MKMapView and Connecting the Outlet
  •         Configuring the Map View
  •         Changing the MapView Region
  •         Changing the Map Type
  •         Testing the iPad MapView Application
  •         Updating the Map View based on User Movement
  •         Adding Basic Annotations to a Map View
    Accessing the iPad Camera and Photo Library
  •         The iOS 5 UIImagePickerController Class
  •         Creating and Configuring a UIImagePickerController Instance
  •         Configuring the UIImagePickerController Delegate
  •         Detecting Device Capabilities
  •         Saving Movies and Images
    An Example iOS 5 iPad Camera Application
  •         An Overview of the Application
  •         Creating the Camera Project
  •         Adding Framework Support
  •         Configuring Protocols, Outlets and Actions
  •         Designing the User Interface
  •         Adding another Button to the Toolbar
  •         Implementing the Camera Action Method
  •         Implementing the useCameraRoll Method
  •         Writing the Delegate Methods
  •         Updating viewDidUnload
  •         Building and Running the Application
    Video Playback from within an iOS 5 iPad Application
  •         An Overview of the MPMoviePlayerController Class
  •         Supported Video Formats
  •         The iPad Movie Player Example Application
  •         Adding the MediaPlayer Framework to the Project
  •         Declaring the Action Method and MoviePlayer Instance
  •         Designing the User Interface
  •         Implementing the Action Method
  •         The Target-Action Notification Method
  •         Build and Run the Application
    Playing Audio on an iPad using AVAudioPlayer
  •         Supported Audio Formats
  •         Receiving Playback Notifications
  •         Controlling and Monitoring Playback
  •         Creating the iPad Audio Example Application
  •         Adding the AVFoundation Framework
  •         Adding an Audio File to the Project Resources
  •         Creating Actions and Outlets
  •         Implementing the Action Methods
  •         Creating Initializing the AVAudioPlayer Object
  •         Implementing the AVAudioPlayerDelegate Protocol Methods
  •         Designing the User Interface
  •         Modifying viewDidUnload
  •         Building and Running the Application
    Recording Audio on an iPad with AVAudioRecorder
  •         An Overview of the iPad AVAudioRecorder Tutorial
  •         Creating the Recorder Project
  •         Declarations, Actions and Outlets
  •         Creating the AVAudioRecorder Instance
  •         Implementing the Action Methods
  •         Implementing the Delegate Methods
  •         Designing the User Interface
  •         Updating the viewDidUnload Method
  •         Testing the Application
    Integrating Twitter into iPad iOS 5 Applications
  •         The iOS 5 Twitter Framework
  •         iOS 5 Accounts Framework
  •         The TWTweetComposeViewController Class
    An Example iPad iOS 5 TWTweetComposeViewController Twitter Application
  •         iPad Twitter Application Overview
  •         Creating the TwitterApp Project
  •         Declaring Outlets, Actions and Variables
  •         Creating the TWTweetComposeViewController Instance
  •         Implementing the Action Methods
  •         Updating viewDidUnload
  •         Designing the User Interface
  •         Building and Running the Application
    Preparing and Submitting an iPad iOS 5 Application to the App Store
  •         Generating an iOS Distribution Certificate Signing Request
  •         Submitting the Certificate Signing Request
  •         Installing the Distribution Certificate
  •         Generating an App Store Distribution Provisioning Profile
  •         Adding an Icon to the Application
  •         Archiving the Application for Distribution
  •         Configuring the Application in iTunes Connect