SKIP THE SHIPPING
Use code NOSHIP during checkout to save 40% on eligible eBooks, now through January 5. Shop now.
Register your product to gain access to bonus material or receive a coupon.
This eBook includes the following formats, accessible from your Account page after purchase:
EPUB The open industry format known for its reflowable content and usability on supported mobile devices.
PDF The popular standard, used most often with the free Acrobat® Reader® software.
This eBook requires no passwords or activation to read. We customize your eBook by discreetly watermarking it with your name, making it uniquely yours.
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 at https://github.com/dfsw/icf.
Coverage includes:
Know Your Tools to Build Better iOS Apps
Please visit the website associated with Mastering iOS Frameworks to access the source code here.
Mastering iOS Frameworks: Working with and Parsing JSON
Preface to Mastering iOS Frameworks: Beyond the Basics, Second Edition
Download the sample pages (includes Chapter 9 and Index)
1 UIKit Dynamics 1
The Sample App 1
Introduction to UIKit Dynamics 2
Implementing UIKit Dynamics 3
Gravity 3
Collisions 4
Attachments 7
Springs 8
Snap 9
Push Forces 10
Item Properties 11
In-Depth UIDynamicAnimator and UIDynamicAnimatorDelegate 13
Summary 14
2 Core Location, MapKit, and Geofencing 15
The Sample App 15
Obtaining User Location 16
Requirements and Permissions 16
Checking for Services 19
Starting Location Request 19
Parsing and Understanding Location Data 22
Significant Change Notifications 23
Using GPX Files to Test Specific Locations 23
Displaying Maps 25
Understanding the Coordinate Systems 25
MKMapKit Configuration and Customization 25
Responding to User Interactions 27
Map Annotations and Overlays 28
Adding Annotations 28
Displaying Standard and Custom Annotation Views 31
Draggable Annotation Views 34
Working with Map Overlays 35
Geocoding and Reverse-Geocoding 36
Geocoding an Address 36
Reverse-Geocoding a Location 40
Geofencing 43
Checking for Regional Monitoring Capability 43
Defining Boundaries 44
Monitoring Changes 45
Getting Directions 47
Summary 52
3 Leaderboards 53
The Sample App 53
Spawning a Cactus 55
Cactus Interaction 58
Displaying Life and Score 60
Pausing and Resuming 62
Final Thoughts on Whack-a-Cac 63
iTunes Connect 63
Game Center Manager 66
Authenticating 68
Common Authentication Errors 69
iOS 6 and Newer Authentication 71
Submitting Scores 73
Adding Scores to Whack-a-Cac 76
Presenting Leaderboards 77
Score Challenges 79
Going Further with Leaderboards 81
Summary 83
4 Achievements 85
iTunes Connect 85
Displaying Achievement Progress 87
Game Center Manager and Authentication 88
The Achievement Cache 89
Reporting Achievements 90
Adding Achievement Hooks 92
Completion Banners 93
Achievement Challenges 94
Adding Achievements into Whack-a-Cac 97
Earned or Unearned Achievements 98
Partially Earned Achievements 99
Multiple Session Achievements 101
Piggybacked Achievements and Storing Achievement Precision 102
Timer-Based Achievements 103
Resetting Achievements 104
Going Further with Achievements 105
Summary 107
5 Getting Started with Address Book 109
Why Address Book Support Is Important 109
Limitations of Address Book Programming 110
The Sample App 110
Getting Address Book Up and Running 111
Reading Data from the Address Book 113
Reading Multivalues from the Address Book 114
Understanding Address Book Labels 115
Working with Addresses 116
Address Book Graphical User Interface 118
People Picker 118
Programmatically Creating Contacts 123
Summary 126
6 Working with Music Libraries 127
The Sample App 127
Building a Playback Engine 129
Registering for Playback Notifications 129
User Controls 131
Handling State Changes 132
Duration and Timers 137
Shuffle and Repeat 138
Media Picker 138
Programmatic Picker 141
Playing a Random Song 141
Predicate Song Matching 142
Summary 144
7 Implementing HealthKit 145
Introduction to HealthKit 145
Introduction to Health.app 146
The Sample App 147
Adding HealthKit to a Project 148
Requesting Permission for Health Data 149
Reading Characteristic HealthKit Data 152
Reading and Writing Basic HealthKit Data 152
Reading and Writing Complex HealthKit Data 155
Summary 160
8 Implementing HomeKit 161
The Sample App 161
Introduction to HomeKit 162
Setting Up HomeKit Components 162
Developer Account Setup 163
Enabling HomeKit Capability 163
Home Manager 164
Home 166
Rooms and Zones 168
Accessories 170
Services and Service Groups 176
Actions and Action Sets 178
Testing with the HomeKit Accessory Simulator 179
Scheduling Actions with Triggers 181
Summary 181
9 Working with and Parsing JSON 183
JSON 183
Benefits of Using JSON 183
JSON Resources 184
The Sample App 184
Accessing the Server 184
Getting JSON from the Server 185
Building the Request 185
Inspecting the Response 186
Parsing JSON 186
Displaying the Data 187
Posting a Message 189
Encoding JSON 189
Sending JSON to the Server 191
Summary 193
10 Notifications 195
Differences Between Local and Push Notifications 195
The Sample App 196
App Setup 196
Creating Development Push SSL Certificate 200
Development Provisioning Profile 203
Custom Sound Preparation 208
Registering for Notifications 209
Scheduling Local Notifications 211
Receiving Notifications 212
Push Notification Server 213
Sending the Push Notifications 214
Handling APNs Feedback 215
Summary 216
11 Cloud Persistence with CloudKit 217
CloudKit Basics 217
The Sample App 218
Setting Up a CloudKit Project 218
Account Setup 218
Enabling iCloud Capabilities 220
CloudKit Concepts 220
Containers 220
Databases 221
Records 221
Record Zones 222
Record Identifiers 222
Assets 222
CloudKit Basic Operations 222
Fetching Records 223
Create and Save a Record 224
Update and Save a Record 226
Subscriptions and Push 227
Push Setup 227
Subscribing to Data Changes 227
User Discovery and Management 229
Managing Data in the Dashboard 233
Summary 235
12 Extensions 237
Types of Extensions 237
Today 237
Share 238
Action 238
Photo Editing 238
Document Provider 238
Custom Keyboard 238
Understanding Extensions 238
API Limitations 239
Creating Extensions 240
Today Extension 242
Sharing Code and Information between Host App and Extension 243
Apple Watch Extension 244
Summary 247
13 Handoff 249
The Sample App 249
Handoff Basics 249
Implementing Handoff 251
Creating the User Activity 252
Continuing an Activity 253
Implementing Handoff in Document-Based Apps 255
Summary 257
14 AirPrint 259
AirPrint Printers 259
Testing for AirPrint 261
Printing Text 261
Print Info 262
Setting Page Range 263
UISimpleTextPrintFormatter 263
Error Handling 264
Starting the Print Job 264
Printer Simulator Feedback 265
Print Center 266
UIPrintInteractionControllerDelegate 267
Printing Rendered HTML 268
Printing PDFs 269
Summary 270
15 Getting Up and Running with Core Data 271
Deciding on Core Data 272
Sample App 273
Starting a Core Data Project 274
Core Data Environment 275
Building Your Managed Object Model 278
Creating an Entity 280
Adding Attributes 280
Establishing Relationships 281
Custom Managed Object Subclasses 282
Setting Up Default Data 282
Inserting New Managed Objects 282
Other Default Data Setup Techniques 284
Displaying Your Managed Objects 285
Creating Your Fetch Request 285
Fetching by Object ID 287
Displaying Your Object Data 288
Using Predicates 290
Introducing the Fetched Results Controller 292
Preparing the Fetched Results Controller 292
Integrating Table View and Fetched Results Controller 294
Responding to Core Data Changes 296
Adding, Editing, and Removing Managed Objects 299
Inserting a New Managed Object 299
Removing a Managed Object 300
Editing an Existing Managed Object 301
Saving and Rolling Back Your Changes 301
Summary 303
16 Integrating Twitter and Facebook Using Social Framework 305
The Sample App 305
Logging In 306
Using SLComposeViewController 308
Posting with a Custom Interface 311
Posting to Twitter 311
Posting to Facebook 315
Creating a Facebook App 315
Accessing User Timelines 322
Twitter 322
Facebook 327
Summary 331
17 Working with Background Tasks 333
The Sample App 334
Checking for Background Availability 334
Finishing a Task in the Background 335
Background Task Identifier 336
Expiration Handler 337
Completing the Background Task 337
Implementing Background Activities 339
Types of Background Activities 339
Playing Music in the Background 340
Summary 344
18 Grand Central Dispatch for Performance 345
The Sample App 345
Introduction to Queues 347
Running on the Main Thread 347
Running in the Background 349
Running in an Operation Queue 351
Concurrent Operations 351
Serial Operations 353
Canceling Operations 354
Custom Operations 355
Running in a Dispatch Queue 357
Concurrent Dispatch Queues 357
Serial Dispatch Queues 359
Summary 361
19 Using Keychain and Touch ID to Secure and Access Data 363
The Sample App 364
Setting Up and Using Keychain 364
Setting Up a New KeychainItemWrapper 365
Storing and Retrieving the PIN 366
Keychain Attribute Keys 367
Securing a Dictionary 368
Resetting a Keychain Item 370
Sharing a Keychain Between Apps 370
Keychain Error Codes 372
Implementing Touch ID 372
Summary 374
20 Working with Images and Filters 375
The Sample App 375
Basic Image Data and Display 376
Instantiating an Image 376
Displaying an Image 377
Using the Image Picker 379
Resizing an Image 382
Core Image Filters 383
Filter Categories and Filters 383
Filter Attributes 386
Initializing an Image 388
Rendering a Filtered Image 389
Chaining Filters 390
Feature Detection 391
Setting Up a Face Detector 391
Processing Face Features 392
Summary 394
21 Collection Views 395
The Sample App 395
Introducing Collection Views 396
Setting Up a Collection View 397
Implementing the Collection View Data Source Methods 398
Implementing the Collection View Delegate Methods 401
Customizing Collection View and Flow Layout 403
Basic Customizations 403
Decoration Views 405
Creating Custom Layouts 408
Collection View Animations 413
Collection View Layout Changes 413
Collection View Layout Animations 414
Collection View Change Animations 416
Summary 417
22 Introduction to TextKit 419
The Sample App 420
Introducing NSLayoutManager 420
Detecting Links Dynamically 423
Detecting Hits 424
Exclusion Paths 425
Content Specific Highlighting 427
Changing Font Settings with Dynamic Type 432
Summary 433
23 Gesture Recognizers 435
Types of Gesture Recognizers 435
Basic Gesture Recognizer Usage 436
Introduction to the Sample App 437
Tap Recognizer in Action 438
Pinch Recognizer in Action 440
Multiple Recognizers for a View 441
Gesture Recognizers: Under the Hood 443
Multiple Recognizers for a View: Redux 444
Requiring Gesture Recognizer Failures 446
Custom UIGestureRecognizer Subclasses 448
Summary 448
24 Accessing the Photo Library 449
The Sample App 449
The Photos Framework 450
Using Asset Collections and Assets 451
Permissions 451
Asset Collections 453
Assets 457
Changes in the Photo Library 459
Asset Collection Changes 459
Asset Changes 462
Dealing with Photo Stream 464
Summary 465
25 Passbook and PassKit 467
The Sample App 468
Designing the Pass 468
Pass Types 469
Pass Layout–Boarding Pass 469
Pass Layout–Coupon 470
Pass Layout–Event 471
Pass Layout–Generic 471
Pass Layout–Store Card 472
Pass Presentation 473
Building the Pass 474
Basic Pass Identification 476
Pass Relevance Information 476
Barcode Identification 477
Pass Visual Appearance Information 478
Pass Fields 478
Signing and Packaging the Pass 481
Creating the Pass Type ID 481
Creating the Pass Signing Certificate 483
Creating the Manifest 488
Signing and Packaging the Pass 489
Testing the Pass 489
Interacting with Passes in an App 491
Updating Passes Automatically 501
Summary 502
26 Debugging and Instruments 503
Introduction to Debugging 503
The First Computer Bug 504
Debugging Basics with Xcode 504
Breakpoints 506
Customizing Breakpoints 507
Symbolic and Exception Breakpoints 508
Breakpoint Scope 508
Working with the Debugger 509
Instruments 510
The Instruments Interface 512
Exploring Instruments: The Time Profiler 514
Exploring Instruments: Leaks 516
Going Further with Instruments 519
Summary 519
Index 521