Mastering iOS Frameworks: Beyond the Basics, Second Edition

Book description

Apple’s iOS SDK provides an amazingly powerful collection of frameworks. But it has been difficult to find detailed and useful knowledge about them–until now. With this book’s practical insights and tested code, you can use Apple’s frameworks to create apps that are more innovative and usable…faster and more reliable…more successful and profitable.


Kyle Richter and Joe Keeley focus on intermediate-to-advanced techniques that professional iOS developers can use every day. Their far-reaching coverage ranges from social support to security, Core Data to iCloud–even Apple Watch.


Organized as a convenient modular reference, nearly every chapter contains a complete Objective-C sample project. A multi-chapter Game Center case study shows how multiple iOS features can be combined to do even more.

All source code may be downloaded athttps://github.com/dfsw/icf.

Coverage includes:

  • Adding physics-like animation and behaviors to UIViews

  • Using Core Location to determine device location, display customized maps, and implement geofencing

  • Making games and apps social with Leaderboards

  • Accessing music and image collections

  • Building health/fitness apps with HealthKit

  • Integrating with home automation via HomeKit

  • Passing data between platforms using JSON

  • Setting up local and remote notifications

  • Remotely storing and syncing data with CloudKit

  • Accessing app functionality with extensions

  • Effortlessly adding AirPrint support

  • Providing Handoff continuity between iOS 8 and Yosemite devices

  • Getting productive with Core Data

  • Integrating Twitter and Facebook via Social Framework

  • Performing resource-intensive tasks with Grand Central Dispatch

  • Securing user data with Keychain and Touch ID

  • Customizing collection views

  • Making the most of gesture recognizers

  • Creating and distributing “passes”

  • Debugging, instrumenting, and profiling apps

  • Table of contents

    1. About This eBook
    2. Title Page
    3. Copyright Page
    4. Dedication Page
    5. Table of Contents
    6. Foreword
    7. Preface
      1. Prerequisites
      2. What You’ll Need
      3. How This Book Is Organized
      4. About the Sample Code
        1. Getting the Sample Code
        2. Installing Git and Working with GitHub
        3. Contacting the Authors
    8. Acknowledgments
    9. About the Authors
    10. 1. UIKit Dynamics
      1. The Sample App
      2. Introduction to UIKit Dynamics
      3. Implementing UIKit Dynamics
        1. Gravity
        2. Collisions
        3. Attachments
        4. Springs
        5. Snap
        6. Push Forces
        7. Item Properties
      4. In-Depth UIDynamicAnimator and UIDynamicAnimatorDelegate
      5. Summary
    11. 2. Core Location, MapKit, and Geofencing
      1. The Sample App
      2. Obtaining User Location
        1. Requirements and Permissions
        2. Checking for Services
        3. Starting Location Request
        4. Parsing and Understanding Location Data
        5. Significant Change Notifications
        6. Using GPX Files to Test Specific Locations
      3. Displaying Maps
        1. Understanding the Coordinate Systems
        2. MKMapKit Configuration and Customization
        3. Responding to User Interactions
      4. Map Annotations and Overlays
        1. Adding Annotations
        2. Displaying Standard and Custom Annotation Views
        3. Draggable Annotation Views
        4. Working with Map Overlays
      5. Geocoding and Reverse-Geocoding
        1. Geocoding an Address
        2. Reverse-Geocoding a Location
      6. Geofencing
        1. Checking for Regional Monitoring Capability
        2. Defining Boundaries
        3. Monitoring Changes
      7. Getting Directions
      8. Summary
    12. 3. Leaderboards
      1. The Sample App
        1. Spawning a Cactus
        2. Cactus Interaction
        3. Displaying Life and Score
        4. Pausing and Resuming
        5. Final Thoughts on Whack-a-Cac
      2. iTunes Connect
      3. Game Center Manager
      4. Authenticating
        1. Common Authentication Errors
        2. iOS 6 and Newer Authentication
      5. Submitting Scores
        1. Adding Scores to Whack-a-Cac
        2. Presenting Leaderboards
        3. Score Challenges
        4. Going Further with Leaderboards
      6. Summary
    13. 4. Achievements
      1. iTunes Connect
      2. Displaying Achievement Progress
      3. Game Center Manager and Authentication
      4. The Achievement Cache
      5. Reporting Achievements
      6. Adding Achievement Hooks
      7. Completion Banners
      8. Achievement Challenges
      9. Adding Achievements into Whack-a-Cac
        1. Earned or Unearned Achievements
        2. Partially Earned Achievements
        3. Multiple Session Achievements
        4. Piggybacked Achievements and Storing Achievement Precision
        5. Timer-Based Achievements
      10. Resetting Achievements
      11. Going Further with Achievements
      12. Summary
    14. 5. Getting Started with Address Book
      1. Why Address Book Support Is Important
      2. Limitations of Address Book Programming
      3. The Sample App
      4. Getting Address Book Up and Running
        1. Reading Data from the Address Book
        2. Reading Multivalues from the Address Book
        3. Understanding Address Book Labels
        4. Working with Addresses
      5. Address Book Graphical User Interface
        1. People Picker
      6. Programmatically Creating Contacts
      7. Summary
    15. 6. Working with Music Libraries
      1. The Sample App
      2. Building a Playback Engine
        1. Registering for Playback Notifications
        2. User Controls
        3. Handling State Changes
        4. Duration and Timers
        5. Shuffle and Repeat
      3. Media Picker
      4. Programmatic Picker
        1. Playing a Random Song
        2. Predicate Song Matching
      5. Summary
    16. 7. Implementing HealthKit
      1. Introduction to HealthKit
      2. Introduction to Health.app
      3. The Sample App
      4. Adding HealthKit to a Project
      5. Requesting Permission for Health Data
      6. Reading Characteristic HealthKit Data
      7. Reading and Writing Basic HealthKit Data
      8. Reading and Writing Complex HealthKit Data
      9. Summary
    17. 8. Implementing HomeKit
      1. The Sample App
      2. Introduction to HomeKit
      3. Setting Up HomeKit Components
        1. Developer Account Setup
        2. Enabling HomeKit Capability
        3. Home Manager
        4. Home
        5. Rooms and Zones
        6. Accessories
        7. Services and Service Groups
        8. Actions and Action Sets
      4. Testing with the HomeKit Accessory Simulator
      5. Scheduling Actions with Triggers
      6. Summary
    18. 9. Working with and Parsing JSON
      1. JSON
        1. Benefits of Using JSON
        2. JSON Resources
      2. The Sample App
      3. Accessing the Server
      4. Getting JSON from the Server
        1. Building the Request
        2. Inspecting the Response
        3. Parsing JSON
        4. Displaying the Data
      5. Posting a Message
        1. Encoding JSON
        2. Sending JSON to the Server
      6. Summary
    19. 10. Notifications
      1. Differences Between Local and Push Notifications
      2. The Sample App
      3. App Setup
      4. Creating Development Push SSL Certificate
      5. Development Provisioning Profile
      6. Custom Sound Preparation
      7. Registering for Notifications
      8. Scheduling Local Notifications
      9. Receiving Notifications
      10. Push Notification Server
      11. Sending the Push Notifications
      12. Handling APNs Feedback
      13. Summary
    20. 11. Cloud Persistence with CloudKit
      1. CloudKit Basics
      2. The Sample App
      3. Setting Up a CloudKit Project
        1. Account Setup
        2. Enabling iCloud Capabilities
      4. CloudKit Concepts
        1. Containers
        2. Databases
        3. Records
        4. Record Zones
        5. Record Identifiers
        6. Assets
      5. CloudKit Basic Operations
        1. Fetching Records
        2. Create and Save a Record
        3. Update and Save a Record
      6. Subscriptions and Push
        1. Push Setup
        2. Subscribing to Data Changes
      7. User Discovery and Management
      8. Managing Data in the Dashboard
      9. Summary
    21. 12. Extensions
      1. Types of Extensions
        1. Today
        2. Share
        3. Action
        4. Photo Editing
        5. Document Provider
        6. Custom Keyboard
      2. Understanding Extensions
      3. API Limitations
      4. Creating Extensions
      5. Today Extension
      6. Sharing Code and Information between Host App and Extension
      7. Apple Watch Extension
      8. Summary
    22. 13. Handoff
      1. The Sample App
      2. Handoff Basics
      3. Implementing Handoff
        1. Creating the User Activity
        2. Continuing an Activity
      4. Implementing Handoff in Document-Based Apps
      5. Summary
    23. 14. AirPrint
      1. AirPrint Printers
      2. Testing for AirPrint
      3. Printing Text
        1. Print Info
        2. Setting Page Range
        3. UISimpleTextPrintFormatter
        4. Error Handling
        5. Starting the Print Job
        6. Printer Simulator Feedback
      4. Print Center
        1. UIPrintInteractionControllerDelegate
      5. Printing Rendered HTML
      6. Printing PDFs
      7. Summary
    24. 15. Getting Up and Running with Core Data
      1. Deciding on Core Data
      2. Sample App
      3. Starting a Core Data Project
        1. Core Data Environment
      4. Building Your Managed Object Model
        1. Creating an Entity
        2. Adding Attributes
        3. Establishing Relationships
        4. Custom Managed Object Subclasses
      5. Setting Up Default Data
        1. Inserting New Managed Objects
        2. Other Default Data Setup Techniques
      6. Displaying Your Managed Objects
        1. Creating Your Fetch Request
        2. Fetching by Object ID
        3. Displaying Your Object Data
        4. Using Predicates
      7. Introducing the Fetched Results Controller
        1. Preparing the Fetched Results Controller
        2. Integrating Table View and Fetched Results Controller
        3. Responding to Core Data Changes
      8. Adding, Editing, and Removing Managed Objects
        1. Inserting a New Managed Object
        2. Removing a Managed Object
        3. Editing an Existing Managed Object
        4. Saving and Rolling Back Your Changes
      9. Summary
    25. 16. Integrating Twitter and Facebook Using Social Framework
      1. The Sample App
      2. Logging In
      3. Using SLComposeViewController
      4. Posting with a Custom Interface
        1. Posting to Twitter
        2. Posting to Facebook
        3. Creating a Facebook App
      5. Accessing User Timelines
        1. Twitter
        2. Facebook
      6. Summary
    26. 17. Working with Background Tasks
      1. The Sample App
      2. Checking for Background Availability
      3. Finishing a Task in the Background
        1. Background Task Identifier
        2. Expiration Handler
        3. Completing the Background Task
      4. Implementing Background Activities
        1. Types of Background Activities
        2. Playing Music in the Background
      5. Summary
    27. 18. Grand Central Dispatch for Performance
      1. The Sample App
      2. Introduction to Queues
      3. Running on the Main Thread
      4. Running in the Background
      5. Running in an Operation Queue
        1. Concurrent Operations
        2. Serial Operations
        3. Canceling Operations
        4. Custom Operations
      6. Running in a Dispatch Queue
        1. Concurrent Dispatch Queues
        2. Serial Dispatch Queues
      7. Summary
    28. 19. Using Keychain and Touch ID to Secure and Access Data
      1. The Sample App
      2. Setting Up and Using Keychain
        1. Setting Up a New KeychainItemWrapper
        2. Storing and Retrieving the PIN
        3. Keychain Attribute Keys
        4. Securing a Dictionary
        5. Resetting a Keychain Item
        6. Sharing a Keychain Between Apps
        7. Keychain Error Codes
      3. Implementing Touch ID
      4. Summary
    29. 20. Working with Images and Filters
      1. The Sample App
      2. Basic Image Data and Display
        1. Instantiating an Image
        2. Displaying an Image
        3. Using the Image Picker
        4. Resizing an Image
      3. Core Image Filters
        1. Filter Categories and Filters
        2. Filter Attributes
        3. Initializing an Image
        4. Rendering a Filtered Image
        5. Chaining Filters
      4. Feature Detection
        1. Setting Up a Face Detector
        2. Processing Face Features
      5. Summary
    30. 21. Collection Views
      1. The Sample App
      2. Introducing Collection Views
        1. Setting Up a Collection View
        2. Implementing the Collection View Data Source Methods
        3. Implementing the Collection View Delegate Methods
      3. Customizing Collection View and Flow Layout
        1. Basic Customizations
        2. Decoration Views
      4. Creating Custom Layouts
      5. Collection View Animations
        1. Collection View Layout Changes
        2. Collection View Layout Animations
        3. Collection View Change Animations
      6. Summary
    31. 22. Introduction to TextKit
      1. The Sample App
      2. Introducing NSLayoutManager
      3. Detecting Links Dynamically
      4. Detecting Hits
      5. Exclusion Paths
      6. Content Specific Highlighting
      7. Changing Font Settings with Dynamic Type
      8. Summary
    32. 23. Gesture Recognizers
      1. Types of Gesture Recognizers
      2. Basic Gesture Recognizer Usage
      3. Introduction to the Sample App
        1. Tap Recognizer in Action
        2. Pinch Recognizer in Action
      4. Multiple Recognizers for a View
        1. Gesture Recognizers: Under the Hood
        2. Multiple Recognizers for a View: Redux
        3. Requiring Gesture Recognizer Failures
      5. Custom UIGestureRecognizer Subclasses
      6. Summary
    33. 24. Accessing the Photo Library
      1. The Sample App
      2. The Photos Framework
      3. Using Asset Collections and Assets
        1. Permissions
        2. Asset Collections
        3. Assets
      4. Changes in the Photo Library
        1. Asset Collection Changes
        2. Asset Changes
      5. Dealing with Photo Stream
      6. Summary
    34. 25. Passbook and PassKit
      1. The Sample App
      2. Designing the Pass
        1. Pass Types
        2. Pass Layout—Boarding Pass
        3. Pass Layout—Coupon
        4. Pass Layout—Event
        5. Pass Layout—Generic
        6. Pass Layout—Store Card
        7. Pass Presentation
      3. Building the Pass
        1. Basic Pass Identification
        2. Pass Relevance Information
        3. Barcode Identification
        4. Pass Visual Appearance Information
        5. Pass Fields
      4. Signing and Packaging the Pass
        1. Creating the Pass Type ID
        2. Creating the Pass Signing Certificate
        3. Creating the Manifest
        4. Signing and Packaging the Pass
        5. Testing the Pass
        6. Interacting with Passes in an App
      5. Updating Passes Automatically
      6. Summary
    35. 26. Debugging and Instruments
      1. Introduction to Debugging
        1. The First Computer Bug
        2. Debugging Basics with Xcode
      2. Breakpoints
        1. Customizing Breakpoints
        2. Symbolic and Exception Breakpoints
        3. Breakpoint Scope
      3. Working with the Debugger
      4. Instruments
        1. The Instruments Interface
        2. Exploring Instruments: The Time Profiler
        3. Exploring Instruments: Leaks
        4. Going Further with Instruments
      5. Summary
    36. Index
    37. Code Snippets

    Product information

    • Title: Mastering iOS Frameworks: Beyond the Basics, Second Edition
    • Author(s):
    • Release date: April 2015
    • Publisher(s): Addison-Wesley Professional
    • ISBN: 9780134052533