Solutions for iOS Developers
1234567

Overcome the vexing issues you’re likely to face when creating apps for the iPhone, iPad, or iPod touch. With new and thoroughly revised recipes in this updated cookbook, you’ll quickly learn the steps necessary to work with the iOS 7 SDK, including solutions for bringing real-world physics and movement to your apps with UIKit Dynamics APIs.

You’ll learn hundreds of techniques for storing and protecting data, sending and receiving notifications, enhancing and animating graphics, managing files and folders, and many other options. Each recipe includes sample code you can use right away.

  • Create vibrant and lifelike user interfaces with UIKit Dynamics
  • Use the Keychain to protect your app’s data
  • Develop location-aware and multitasking-aware apps
  • Work with iOS 7’s audio and video APIs
  • Use Event Kit UI to manage calendars, dates, and events
  • Take advantage of the accelerometer and the gyroscope
  • Integrate iCloud into your apps
  • Define the layout of UI elements with Auto Layout
  • Get working examples for implementing gesture recognizers
  • Retrieve and manipulate contacts and groups from the Address Book
  • Determine a camera’s availability and access the Photo Library

Vandad Nahavandipoor

Vandad Nahavandipoor is currently an iOS programmer for a leading digital media distributor in London, United Kingdom. He has led an international team of more than 30 iOS developers in his previous job. Some of the projects he has lead include the NatWest and the RBS iOS apps running on millions of iPhones and iPads in the UK. Vandad received his B.Sc and M.Sc in Information Technology for E-Commerce from the University of Sussex in England.

Vandad's programming experience started when he first learned Basic on his father's Commodore 64. He then took this experience and applied it on his uncle's Intel 186 computer, running Basic on DOS. At this point, he found programming for personal computers exciting indeed and moved on to learn Object Pascal. This allowed him to learn Borland Delphi quite easily. He wrote a short 400 pages book on Borland Delphi and dedicated the book to Borland. From then, he picked up x86 Assembly programming and wrote a hobby 32-bit operating system named Vandior. It wasn't until late 2007 when iOS programming became his main focus.

Aside from programming, Vandad is a road cyclist, enjoying friendly competition in cyclosportive events in England and traveling long distance on his bicycle to other European countries every now and then. He also enjoys tinkering with his piano and playing electric guitar. Some of his electric guitar performances are available on YouTube.

  1. Chapter 1 Implementing Controllers and Views

    1. Introduction

    2. Displaying Alerts with UIAlertView

    3. Creating and Using Switches with UISwitch

    4. Customizing the UISwitch

    5. Picking Values with the UIPickerView

    6. Picking the Date and Time with UIDatePicker

    7. Implementing Range Pickers with UISlider

    8. Customizing the UISlider

    9. Grouping Compact Options with UISegmentedControl

    10. Presenting and Managing Views with UIViewController

    11. Presenting Sharing Options with UIActivityViewController

    12. Presenting Custom Sharing Options with UIActivityViewController

    13. Implementing Navigation with UINavigationController

    14. Manipulating a Navigation Controller’s Array of View Controllers

    15. Displaying an Image on a Navigation Bar

    16. Adding Buttons to Navigation Bars Using UIBarButtonItem

    17. Presenting Multiple View Controllers with UITabBarController

    18. Displaying Static Text with UILabel

    19. Customizing the UILabel

    20. Accepting User Text Input with UITextField

    21. Displaying Long Lines of Text with UITextView

    22. Adding Buttons to the User Interface with UIButton

    23. Displaying Images with UIImageView

    24. Creating Scrollable Content with UIScrollView

    25. Loading Web Pages with UIWebView

    26. Displaying Progress with UIProgressView

    27. Constructing and Displaying Styled Texts

    28. Presenting Master-Detail Views with UISplitViewController

    29. Enabling Paging with UIPageViewController

    30. Displaying Popovers with UIPopoverController

  2. Chapter 2 Creating Dynamic and Interactive User Interfaces

    1. Introduction

    2. Adding Gravity to Your UI Components

    3. Detecting and Reacting to Collisions Between UI Components

    4. Animating Your UI Components with a Push

    5. Attaching Multiple Dynamic Items to Each Other

    6. Adding a Dynamic Snap Effect to Your UI Components

    7. Assigning Characteristics to Your Dynamic Effects

  3. Chapter 3 Auto Layout and the Visual Format Language

    1. Introduction

    2. Placing UI Components in the Center of the Screen

    3. Defining Horizontal and Vertical Constraints with the Visual Format Language

    4. Utilizing Cross View Constraints

    5. Configuring Auto Layout Constraints in Interface Builder

  4. Chapter 4 Constructing and Using Table Views

    1. Introduction

    2. Populating a Table View with Data

    3. Using Different Types of Accessories in a Table View Cell

    4. Creating Custom Table View Cell Accessories

    5. Enabling Swipe Deletion of Table View Cells

    6. Constructing Headers and Footers in Table Views

    7. Displaying Context Menus on Table View Cells

    8. Moving Cells and Sections in Table Views

    9. Deleting Cells and Sections from Table Views

    10. Utilizing the UITableViewController for Easy Creation of Table Views

    11. Displaying a Refresh Control for Table Views

  5. Chapter 5 Building Complex Layouts with Collection Views

    1. Introduction

    2. Constructing Collection Views

    3. Assigning a Data Source to a Collection View

    4. Providing a Flow Layout to a Collection View

    5. Providing Basic Content to a Collection View

    6. Feeding Custom Cells to Collection Views Using .xib Files

    7. Handling Events in Collection Views

    8. Providing a Header and a Footer in a Flow Layout

    9. Adding Custom Interactions to Collection Views

    10. Providing Contextual Menus on Collection View Cells

  6. Chapter 6 Storyboards

    1. Introduction

    2. Adding a Navigation Controller to a Storyboard

    3. Passing Data from One Screen to Another

    4. Adding a Tab Bar Controller to a Storyboard

    5. Introducing Custom Segue Transitions to Your Storyboard

    6. Placing Images and Other UI Components on Storyboards

  7. Chapter 7 Concurrency

    1. Introduction

    2. Constructing Block Objects

    3. Accessing Variables in Block Objects

    4. Invoking Block Objects

    5. Performing UI-Related Tasks with GCD

    6. Executing Non-UI Related Tasks Synchronously with GCD

    7. Executing Non-UI Related Tasks Asynchronously with GCD

    8. Performing Tasks after a Delay with GCD

    9. Performing a Task Only Once with GCD

    10. Grouping Tasks Together with GCD

    11. Constructing Your Own Dispatch Queues with GCD

    12. Running Tasks Synchronously with Operations

    13. Running Tasks Asynchronously with Operations

    14. Creating Dependency Between Operations

    15. Creating Timers

    16. Creating Concurrency with Threads

    17. Invoking Background Methods

    18. Exiting Threads and Timers

  8. Chapter 8 Security

    1. Introduction

    2. Enabling Security and Protection for Your Apps

    3. Storing Values in the Keychain

    4. Finding Values in the Keychain

    5. Updating Existing Values in the Keychain

    6. Deleting Exiting Values in the Keychain

    7. Sharing Keychain Data Between Multiple Apps

    8. Writing to and Reading Keychain Data from iCloud

    9. Storing Files Securely in the App Sandbox

    10. Securing Your User Interface

  9. Chapter 9 Core Location and Maps

    1. Introduction

    2. Creating a Map View

    3. Handling the Events of a Map View

    4. Pinpointing the Location of a Device

    5. Displaying Pins on a Map View

    6. Displaying Pins with Different Colors on a Map View

    7. Displaying Custom Pins on a Map View

    8. Converting Meaningful Addresses to Longitude and Latitude

    9. Converting Longitude and Latitude to a Meaningful Address

    10. Searching on a Map View

    11. Displaying Directions on the Map

  10. Chapter 10 Implementing Gesture Recognizers

    1. Introduction

    2. Detecting Swipe Gestures

    3. Detecting Rotation Gestures

    4. Detecting Panning and Dragging Gestures

    5. Detecting Long-Press Gestures

    6. Detecting Tap Gestures

    7. Detecting Pinch Gestures

  11. Chapter 11 Networking, JSON, XML, and Sharing

    1. Introduction

    2. Downloading Asynchronously with NSURLConnection

    3. Handling Timeouts in Asynchronous Connections

    4. Downloading Synchronously with NSURLConnection

    5. Modifying a URL Request with NSMutableURLRequest

    6. Sending HTTP GET Requests with NSURLConnection

    7. Sending HTTP POST Requests with NSURLConnection

    8. Sending HTTP DELETE Requests with NSURLConnection

    9. Sending HTTP PUT Requests with NSURLConnection

    10. Serializing Arrays and Dictionaries into JSON

    11. Deserializing JSON into Arrays and Dictionaries

    12. Integrating Social Sharing into Your Apps

    13. Parsing XML with NSXMLParser

  12. Chapter 12 Audio and Video

    1. Introduction

    2. Playing Audio Files

    3. Handling Interruptions While Playing Audio

    4. Recording Audio

    5. Handling Interruptions While Recording Audio

    6. Playing Audio over Other Active Sounds

    7. Playing Video Files

    8. Capturing Thumbnails from Video Files

    9. Accessing the Music Library

  13. Chapter 13 Address Book

    1. Introduction

    2. Requesting Access to the Address Book

    3. Retrieving a Reference to an Address Book

    4. Retrieving All the People in the Address Book

    5. Retrieving Properties of Address Book Entries

    6. Inserting a Person Entry into the Address Book

    7. Inserting a Group Entry into the Address Book

    8. Adding Persons to Groups

    9. Searching the Address Book

    10. Retrieving and Setting a Person's Address Book Image

  14. Chapter 14 Files and Folder Management

    1. Introduction

    2. Finding the Paths of the Most Useful Folders on Disk

    3. Writing to and Reading from Files

    4. Creating Folders on Disk

    5. Enumerating Files and Folders

    6. Deleting Files and Folders

    7. Saving Objects to Files

  15. Chapter 15 Camera and the Photo Library

    1. Introduction

    2. Detecting and Probing the Camera

    3. Taking Photos with the Camera

    4. Taking Videos with the Camera

    5. Storing Photos in the Photo Library

    6. Storing Videos in the Photo Library

    7. Retrieving Photos and Videos from the Photo Library

    8. Retrieving Assets from the Assets Library

    9. Editing Videos on an iOS Device

  16. Chapter 16 Multitasking

    1. Introduction

    2. Detecting the Availability of Multitasking

    3. Completing a Long-Running Task in the Background

    4. Adding Background Fetch Capabilities to Your Apps

    5. Playing Audio in the Background

    6. Handling Location Changes in the Background

    7. Saving and Loading the State of Multitasking Apps

    8. Handling Network Connections in the Background

    9. Opting Out of Multitasking

  17. Chapter 17 Notifications

    1. Introduction

    2. Sending Notifications

    3. Listening for and Reacting to Notifications

    4. Listening and Reacting to Keyboard Notifications

    5. Scheduling Local Notifications

    6. Listening for and Reacting to Local Notifications

    7. Handling Local System Notifications

    8. Setting Up Your App for Push Notifications

    9. Delivering Push Notifications to Your App

    10. Reacting to Push Notifications

  18. Chapter 18 Core Data

    1. Introduction

    2. Creating a Core Data Model with Xcode

    3. Generating Class Files for Core Data Entities

    4. Creating and Saving Data Using Core Data

    5. Reading Data from Core Data

    6. Deleting Data from Core Data

    7. Sorting Data in Core Data

    8. Boosting Data Access in Table Views

    9. Implementing Relationships in Core Data

    10. Fetching Data in the Background

    11. Using Custom Data Types in Your Core Data Model

  19. Chapter 19 Dates, Calendars, and Events

    1. Introduction

    2. Requesting Permission to Access Calendars

    3. Retrieving Calendar Groups on an iOS Device

    4. Adding Events to Calendars

    5. Accessing the Contents of Calendars

    6. Removing Events from Calendars

    7. Adding Recurring Events to Calendars

    8. Retrieving the Attendees of an Event

    9. Adding Alarms to Calendars

    10. Handling Event Changed Notifications

    11. Presenting Event View Controllers

    12. Presenting Event Edit View Controllers

  20. Chapter 20 Graphics and Animations

    1. Introduction

    2. Enumerating and Loading Fonts

    3. Drawing Text

    4. Constructing, Setting, and Using Colors

    5. Drawing Images

    6. Constructing Resizable Images

    7. Drawing Lines

    8. Constructing Paths

    9. Drawing Rectangles

    10. Adding Shadows to Shapes

    11. Drawing Gradients

    12. Moving Shapes Drawn on Graphic Contexts

    13. Scaling Shapes Drawn on Graphic Contexts

    14. Rotating Shapes Drawn on Graphic Contexts

    15. Animating and Moving Views

    16. Animating and Scaling Views

    17. Animating and Rotating Views

    18. Capturing a Screenshot of Your View into an Image

  21. Chapter 21 Core Motion

    1. Introduction

    2. Detecting the Availability of an Accelerometer

    3. Detecting the Availability of a Gyroscope

    4. Retrieving Accelerometer Data

    5. Detecting Shakes on an iOS Device

    6. Retrieving Gyroscope Data

  22. Chapter 22 iCloud

    1. Introduction

    2. Setting Up Your App for iCloud

    3. Storing and Synchronizing Dictionaries in iCloud

    4. Creating and Managing Folders for Apps in iCloud

    5. Searching for Files and Folders in iCloud

    6. Storing User Documents in iCloud

    7. Managing the State of Documents in iCloud

  23. Chapter 23 Pass Kit

    1. Introduction

    2. Creating Pass Kit Certificates

    3. Creating Pass Files

    4. Providing Icons and Images for Passes

    5. Preparing Your Passes for Digital Signature

    6. Signing Passes Digitally

    7. Distributing Passes Using Email

    8. Distributing Passes Using Web Services

    9. Enabling Your iOS Apps to Access Passes on iOS Devices

    10. Interacting with Passbook Programmatically

  24. Colophon