Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Making Apple Devices Work Together

Making Apple Devices Work Together

Most of us have more than one iOS device. Whether it’s an iPhone and iPad, iPhone and Apple Watch, or iPad and MacBook, these devices no longer live in isolation. Bound together by iCloud and your Apple ID, these devices are more powerful when they work together. This session will cover making them communicate using new and old APIs alike: Handoff and iCloud. We’ll cover the best way to share files and preferences among all of your users’ devices. If you don’t have a Mac app but do have a website, we’ll cover transferring control back and forth using Handoff, as well as sharing passwords with iCloud Keychain. By the end, this session will have you multitasking like a pro.

Jeff Kelley

June 11, 2015
Tweet

More Decks by Jeff Kelley

Other Decks in Programming

Transcript

  1. What problems are we solving? • Synchronizing data between devices

    • Preventing duplicate effort on the user’s part • Seamlessly transitioning state from one device to the next • Integrating a mobile app with a desktop website
  2. Synchronizing Data Between Devices • Not a problem we’re going

    to solve in this 30 minutes • Tons of solutions out there, both Apple’s and third- party solutions • CloudKit for syncing data using iCloud • With iOS 9, includes JS web service API! • Parse et al. for syncing data with other platforms, too
  3. Synchronizing Data Between Devices • Other kinds of data you

    want to keep in sync • Passwords • iCloud Keychain • Articles to read later • Reading List • Simple data • iCloud Key-Value storage
  4. Implementing iCloud Keychain • Store usernames and passwords just as

    you normally would in the keychain • Square Valet • FXKeychain • Add a new attribute to keychain items: kSecAttrSynchronizable • VALSynchronizableValet
  5. Implementing iCloud Key- Value Storage • Add the iCloud Key-Value

    Store value to your Entitlements.plist • Use NSUbiquitousKeyValueStore like NSUserDefaults • But also keep NSUserDefaults around in case the user signs out of iCloud • Listen for change notifications and update local state
  6. Seamlessly Transitioning State Between Devices • When a user starts

    doing something on one device, they may want to finish on another • Entering long-form text on iPhone instead of Apple Watch • Continuity allows users to use all of their devices together • Handoff is a feature of Continuity that your app can implement
  7. Implementing Handoff • NSUserActivity • Describe what the user is

    doing • Describe the document the user has open with UIDocument or NSDocument • Automatically picked up via Bluetooth on eligible devices
  8. Implementing Handoff override func updateUserActivityState(activity: NSUserActivity) { let resizedImage =

    selectedImage? .resizedImageToFitInSize(CGSize(width: 250, height: 250), scaleIfSmaller: false) let representation = UIImageJPEGRepresentation(resizedImage, 0.5) activity.addUserInfoEntriesFromDictionary(["Image": representation]) super.updateUserActivityState(activity) }
  9. Implementing Handoff func application(application: UIApplication, willContinueUserActivityWithType userActivityType: String) -> Bool

    { return true } func application(application: UIApplication, continueUserActivity userActivity: NSUserActivity, restorationHandler: ([AnyObject]!) -> Void) -> Bool { if let navigationController = window?.rootViewController as? UINavigationController, rootViewController = navigationController.viewControllers.first as? ViewController, imageData = userActivity.userInfo?["Image"] as? NSData, image = UIImage(data: imageData) { rootViewController.selectedImage = image } return true }
  10. Other Handoff Uses • Apple Watch uses user activities when

    the user opens your app from: • Glance • ClockKit Complication • If your watch app needs you to open your iPhone app (e.g. to log in to a web service), use Handoff to open it directly onto the login screen • Send documents around between devices • Automatically managed for document-based apps • NSUserActivity is the basis for new app indexing and search
  11. Integrating Your Website • Shared Web Credentials • Add the

    domain(s) with which you’re sharing credentials to the com.apple.developer.associated‑domains entitlement • Add an apple-app-site-association file to the domain(s) • CMS signed by a TLS certificate, HTTPS, no redirects • Validated at install time • Use SecRequestSharedWebCredential() and SecAddSharedWebCredential() to manage password data • Use SecCreateSharedWebCredentialPassword() to suggest passwords like Safari
  12. Integrating Your Website • iOS App to Website • Set

    the webpageURL property of your NSUserActivity • The default browser opens the URL if no app claims the user activity type • Website to iOS App • Add the domain(s) with which you’re handing off data to the com.apple.developer.associated‑domains entitlement • Add an apple-app-site-association file to the domain(s) • Respond to NSUserActivityTypeBrowsingWeb