You are previewing iOS 7 Programming Cookbook.
O'Reilly logo
iOS 7 Programming Cookbook

Book Description

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 ways to store and protect data, send and receive notifications, enhance and animate graphics, manage files and folders, and take advantage of UI Dynamics.

Table of Contents

  1. Preface
    1. Audience
    2. Organization of This Book
    3. Additional Resources
    4. Conventions Used in This Book
    5. Using Code Examples
    6. Safari® Books Online
    7. How to Contact Us
    8. Acknowledgments
  2. 1. Implementing Controllers and Views
    1. 1.0. Introduction
    2. 1.1. Displaying Alerts with UIAlertView
    3. 1.2. Creating and Using Switches with UISwitch
    4. 1.3. Customizing the UISwitch
    5. 1.4. Picking Values with the UIPickerView
    6. 1.5. Picking the Date and Time with UIDatePicker
    7. 1.6. Implementing Range Pickers with UISlider
    8. 1.7. Customizing the UISlider
    9. 1.8. Grouping Compact Options with UISegmentedControl
    10. 1.9. Presenting and Managing Views with UIViewController
    11. 1.10. Presenting Sharing Options with UIActivityViewController
    12. 1.11. Presenting Custom Sharing Options with UIActivityViewController
    13. 1.12. Implementing Navigation with UINavigationController
    14. 1.13. Manipulating a Navigation Controller’s Array <span xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:pls="http://www.w3.org/2005/01/pronunciation-lexicon" xmlns:ssml="http://www.w3.org/2001/10/synthesis" xmlns:svg="http://www.w3.org/2000/svg">of View Controllers</span>
    15. 1.14. Displaying an Image on a Navigation Bar
    16. 1.15. Adding Buttons to Navigation Bars Using UIBarButtonItem
    17. 1.16. Presenting Multiple View Controllers with UITabBarController
    18. 1.17. Displaying Static Text with UILabel
    19. 1.18. Customizing the UILabel
    20. 1.19. Accepting User Text Input with UITextField
    21. 1.20. Displaying Long Lines of Text with UITextView
    22. 1.21. Adding Buttons to the User Interface with UIButton
    23. 1.22. Displaying Images with UIImageView
    24. 1.23. Creating Scrollable Content with UIScrollView
    25. 1.24. Loading Web Pages with UIWebView
    26. 1.25. Displaying Progress with UIProgressView
    27. 1.26. Constructing and Displaying Styled Texts
    28. 1.27. <span xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:pls="http://www.w3.org/2005/01/pronunciation-lexicon" xmlns:ssml="http://www.w3.org/2001/10/synthesis" xmlns:svg="http://www.w3.org/2000/svg">Presenting Master-Detail Views with UISplitViewController</span>
    29. 1.28. Enabling Paging with UIPageViewController
    30. 1.29. Displaying Popovers with UIPopoverController
  3. 2. Creating Dynamic and Interactive User Interfaces
    1. 2.0. Introduction
    2. 2.1. Adding Gravity to Your UI Components
    3. 2.2. Detecting and Reacting to Collisions Between UI Components
    4. 2.3. Animating Your UI Components with a Push
    5. 2.4. Attaching Multiple Dynamic Items to Each Other
    6. 2.5. Adding a Dynamic Snap Effect to Your UI Components
    7. 2.6. Assigning Characteristics to Your Dynamic Effects
  4. 3. Auto Layout and the Visual Format Language
    1. 3.0. Introduction
    2. 3.1. Placing UI Components in the Center of the Screen
    3. 3.2. Defining Horizontal and Vertical Constraints with the Visual Format Language
    4. 3.3. Utilizing Cross View Constraints
    5. 3.4. Configuring Auto Layout Constraints in Interface Builder
  5. 4. Constructing and Using Table Views
    1. 4.0. Introduction
    2. 4.1. Populating a Table View with Data
    3. 4.2. Using Different Types of Accessories in a Table View Cell
    4. 4.3. Creating Custom Table View Cell Accessories
    5. 4.4. Enabling Swipe Deletion of Table View Cells
    6. 4.5. Constructing Headers and Footers in Table Views
    7. 4.6. Displaying Context Menus on Table View Cells
    8. 4.7. Moving Cells and Sections in Table Views
    9. 4.8. Deleting Cells and Sections from Table Views
    10. 4.9. Utilizing the UITableViewController for Easy Creation of Table Views
    11. 4.10. Displaying a Refresh Control for Table Views
  6. 5. Building Complex Layouts with Collection Views
    1. 5.0. Introduction
    2. 5.1. Constructing Collection Views
    3. 5.2. Assigning a Data Source to a Collection View
    4. 5.3. Providing a Flow Layout to a Collection View
    5. 5.4. Providing Basic Content to a Collection View
    6. 5.5. Feeding Custom Cells to Collection Views Using .xib Files
    7. 5.6. Handling Events in Collection Views
    8. 5.7. Providing a Header and a Footer in a Flow Layout
    9. 5.8. Adding Custom Interactions to Collection Views
    10. 5.9. Providing Contextual Menus on Collection View Cells
  7. 6. Storyboards
    1. 6.0. Introduction
    2. 6.1. Adding a Navigation Controller to a Storyboard
    3. 6.2. Passing Data from One Screen to Another
    4. 6.3. Adding a Tab Bar Controller to a Storyboard
    5. 6.4. Introducing Custom Segue Transitions to Your Storyboard
    6. 6.5. Placing Images and Other UI Components on Storyboards
  8. 7. Concurrency
    1. 7.0. Introduction
    2. 7.1. Constructing Block Objects
    3. 7.2. Accessing Variables in Block Objects
    4. 7.3. Invoking Block Objects
    5. 7.4. Performing UI-Related Tasks with GCD
    6. 7.5. Executing Non-UI Related Tasks Synchronously with GCD
    7. 7.6. Executing Non-UI Related Tasks Asynchronously <span xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:pls="http://www.w3.org/2005/01/pronunciation-lexicon" xmlns:ssml="http://www.w3.org/2001/10/synthesis" xmlns:svg="http://www.w3.org/2000/svg">with GCD</span>
    8. 7.7. Performing Tasks After a Delay with GCD
    9. 7.8. Performing a Task Only Once with GCD
    10. 7.9. Grouping Tasks Together with GCD
    11. 7.10. Constructing Your Own Dispatch Queues with GCD
    12. 7.11. Running Tasks Synchronously with Operations
    13. 7.12. Running Tasks Asynchronously with Operations
    14. 7.13. Creating Dependency Between Operations
    15. 7.14. Creating Timers
    16. 7.15. Creating Concurrency with Threads
    17. 7.16. Invoking Background Methods
    18. 7.17. Exiting Threads and Timers
  9. 8. Security
    1. 8.0. Introduction
    2. 8.1. Enabling Security and Protection for Your Apps
    3. 8.2. Storing Values in the Keychain
    4. 8.3. Finding Values in the Keychain
    5. 8.4. Updating Existing Values in the Keychain
    6. 8.5. Deleting Exiting Values in Keychain
    7. 8.6. Sharing Keychain Data Between Multiple Apps
    8. 8.7. Writing to and Reading Keychain Data from iCloud
    9. 8.8. Storing Files Securely in the App Sandbox
    10. 8.9. Securing Your User Interface
  10. 9. Core Location and Maps
    1. 9.0. Introduction
    2. 9.1. Creating a Map View
    3. 9.2. Handling the Events of a Map View
    4. 9.3. Pinpointing the Location of a Device
    5. 9.4. Displaying Pins on a Map View
    6. 9.5. Displaying Pins with Different Colors on a Map View
    7. 9.6. Displaying Custom Pins on a Map View
    8. 9.7. Converting Meaningful Addresses to Longitude and Latitude
    9. 9.8. Converting Longitude and Latitude to a Meaningful Address
    10. 9.9. Searching on a Map View
    11. 9.10. Displaying Directions on the Map
  11. 10. Implementing Gesture Recognizers
    1. 10.0. Introduction
    2. 10.1. Detecting Swipe Gestures
    3. 10.2. Detecting Rotation Gestures
    4. 10.3. Detecting Panning and Dragging Gestures
    5. 10.4. Detecting Long Press Gestures
    6. 10.5. Detecting Tap Gestures
    7. 10.6. Detecting Pinch Gestures
  12. 11. Networking, JSON, XML, and Sharing
    1. 11.0. Introduction
    2. 11.1. Downloading Asynchronously with NSURLConnection
    3. 11.2. Handling Timeouts in Asynchronous Connections
    4. 11.3. Downloading Synchronously with NSURLConnection
    5. 11.4. Modifying a URL Request with NSMutableURLRequest
    6. 11.5. Sending HTTP GET Requests with NSURLConnection
    7. 11.6. Sending HTTP POST Requests with NSURLConnection
    8. 11.7. Sending HTTP DELETE Requests with NSURLConnection
    9. 11.8. Sending HTTP PUT Requests with NSURLConnection
    10. 11.9. Serializing Arrays and Dictionaries into JSON
    11. 11.10. Deserializing JSON into Arrays and Dictionaries
    12. 11.11. Integrating Social Sharing into Your Apps
    13. 11.12. Parsing XML with NSXMLParser
  13. 12. Audio and Video
    1. 12.0. Introduction
    2. 12.1. Playing Audio Files
    3. 12.2. Handling Interruptions While Playing Audio
    4. 12.3. Recording Audio
    5. 12.4. Handling Interruptions While Recording Audio
    6. 12.5. Playing Audio over Other Active Sounds
    7. 12.6. Playing Video Files
    8. 12.7. Capturing Thumbnails from Video Files
    9. 12.8. Accessing the Music Library
  14. 13. Address Book
    1. 13.0. Introduction
    2. 13.1. Requesting Access to the Address Book
    3. 13.2. Retrieving a Reference to an Address Book
    4. 13.3. Retrieving All the People in the Address Book
    5. 13.4. Retrieving Properties of Address Book Entries
    6. 13.5. Inserting a Person Entry into the Address Book
    7. 13.6. Inserting a Group Entry into the Address Book
    8. 13.7. Adding Persons to Groups
    9. 13.8. Searching the Address Book
    10. 13.9. Retrieving and Setting a Person’s Address Book Image
  15. 14. Files and Folder Management
    1. 14.0. Introduction
    2. 14.1. Finding the Paths of the Most Useful Folders on Disk
    3. 14.2. Writing to and Reading from Files
    4. 14.3. Creating Folders on Disk
    5. 14.4. Enumerating Files and Folders
    6. 14.5. Deleting Files and Folders
    7. 14.6. Saving Objects to Files
  16. 15. Camera and the Photo Library
    1. 15.0. Introduction
    2. 15.1. Detecting and Probing the Camera
    3. 15.2. Taking Photos with the Camera
    4. 15.3. Taking Videos with the Camera
    5. 15.4. Storing Photos in the Photo Library
    6. 15.5. Storing Videos in the Photo Library
    7. 15.6. Retrieving Photos and Videos from the Photo Library
    8. 15.7. Retrieving Assets from the Assets Library
    9. 15.8. Editing Videos on an iOS Device
  17. 16. Multitasking
    1. 16.0. Introduction
    2. 16.1. Detecting the Availability of Multitasking
    3. 16.2. Completing a Long-Running Task in the Background
    4. 16.3. Adding Background Fetch Capabilities to Your Apps
    5. 16.4. Playing Audio in the Background
    6. 16.5. Handling Location Changes in the Background
    7. 16.6. Saving and Loading the State of Multitasking Apps
    8. 16.7. Handling Network Connections in the Background
    9. 16.8. Opting Out of Multitasking
  18. 17. Notifications
    1. 17.0. Introduction
    2. 17.1. Sending Notifications
    3. 17.2. Listening for and Reacting to Notifications
    4. 17.3. Listening and Reacting to Keyboard Notifications
    5. 17.4. Scheduling Local Notifications
    6. 17.5. Listening for and Reacting to Local Notifications
    7. 17.6. Handling Local System Notifications
    8. 17.7. Setting Up Your App for Push Notifications
    9. 17.8. Delivering Push Notifications to Your App
    10. 17.9. Reacting to Push Notifications
  19. 18. Core Data
    1. 18.0. Introduction
    2. 18.1. Creating a Core Data Model with Xcode
    3. 18.2. Generating Class Files for Core Data Entities
    4. 18.3. Creating and Saving Data Using Core Data
    5. 18.4. Reading Data from Core Data
    6. 18.5. Deleting Data from Core Data
    7. 18.6. Sorting Data in Core Data
    8. 18.7. Boosting Data Access in Table Views
    9. 18.8. Implementing Relationships in Core Data
    10. 18.9. Fetching Data in the Background
    11. 18.10. Using Custom Data Types in Your Core Data Model
  20. 19. Dates, Calendars, and Events
    1. 19.0. Introduction
    2. 19.1. Requesting Permission to Access Calendars
    3. 19.2. Retrieving Calendar Groups on an iOS Device
    4. 19.3. Adding Events to Calendars
    5. 19.4. Accessing the Contents of Calendars
    6. 19.5. Removing Events from Calendars
    7. 19.6. Adding Recurring Events to Calendars
    8. 19.7. Retrieving the Attendees of an Event
    9. 19.8. Adding Alarms to Calendars
    10. 19.9. Handling Event Changed Notifications
    11. 19.10. Presenting Event View Controllers
    12. 19.11. Presenting Event Edit View Controllers
  21. 20. Graphics and Animations
    1. 20.0. Introduction
    2. 20.1. Enumerating and Loading Fonts
    3. 20.2. Drawing Text
    4. 20.3. Constructing, Setting, and Using Colors
    5. 20.4. Drawing Images
    6. 20.5. Constructing Resizable Images
    7. 20.6. Drawing Lines
    8. 20.7. Constructing Paths
    9. 20.8. Drawing Rectangles
    10. 20.9. Adding Shadows to Shapes
    11. 20.10. Drawing Gradients
    12. 20.11. Moving Shapes Drawn on Graphic Contexts
    13. 20.12. Scaling Shapes Drawn on Graphic Contexts
    14. 20.13. Rotating Shapes Drawn on Graphic Contexts
    15. 20.14. Animating and Moving Views
    16. 20.15. Animating and Scaling Views
    17. 20.16. Animating and Rotating Views
    18. 20.17. Capturing a Screenshot of Your View into an Image
  22. 21. Core Motion
    1. 21.0. Introduction
    2. 21.1. Detecting the Availability of an Accelerometer
    3. 21.2. Detecting the Availability of a Gyroscope
    4. 21.3. Retrieving Accelerometer Data
    5. 21.4. Detecting Shakes on an iOS Device
    6. 21.5. Retrieving Gyroscope Data
  23. 22. iCloud
    1. 22.0. Introduction
    2. 22.1. Setting Up Your App for iCloud
    3. 22.2. Storing and Synchronizing Dictionaries in iCloud
    4. 22.3. Creating and Managing Folders for Apps in iCloud
    5. 22.4. Searching for Files and Folders in iCloud
    6. 22.5. Storing User Documents in iCloud
    7. 22.6. Managing the State of Documents in iCloud
  24. 23. Pass Kit
    1. 23.0. Introduction
    2. 23.1. Creating Pass Kit Certificates
    3. 23.2. Creating Pass Files
    4. 23.3. Providing Icons and Images for Passes
    5. 23.4. Preparing Your Passes for Digital Signature
    6. 23.5. Signing Passes Digitally
    7. 23.6. Distributing Passes Using Email
    8. 23.7. Distributing Passes Using Web Services
    9. 23.8. Enabling Your iOS Apps to Access Passes on iOS Devices
    10. 23.9. Interacting with Passbook Programmatically
  25. Index
  26. About the Author
  27. Colophon
  28. Copyright