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


  1. Making Apple Devices Work Together Jeff Kelley (@SlaunchaMan) AltConf, June

    11th, 2015
  2. None
  3. 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
  4. 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
  5. 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
  6. 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
  7. 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
  8. Demo

  9. 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
  10. 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
  11. Implementing Handoff let userActivity = NSUserActivity( activityType: "com.slaunchaman.PhotoSharer.viewingPhoto") userActivity.title =

    "Viewing Image" self.userActivity = userActivity self.userActivity?.becomeCurrent()
  12. 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) }
  13. 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 }
  14. Demo

  15. 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
  16. Integrating Your Website • Shared Web Credentials • Add the

    domain(s) with which you’re sharing credentials to the‑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
  17. 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‑domains entitlement • Add an apple-app-site-association file to the domain(s) • Respond to NSUserActivityTypeBrowsingWeb
  18. For More Info • • documentation/Security/Reference/ SharedWebCredentialsRef/ • streams/ •