$30 off During Our Annual Pro Sale. View Details »

Siri Shortcuts - Swift Heroes, Torino, Italy, November 2018

Siri Shortcuts - Swift Heroes, Torino, Italy, November 2018

Updated talk on the history of Shortcuts, my co-worker named Siri, and the new iOS 12 APIs you can use to start creating your own (semi-limited) shortcuts.

Now with way more info about configuring responses, setting up an intents UI extension, and some crazy things one developer has done to try to bend Intent-powered shortcuts to his will.

Sample code available at https://github.com/designatednerd/TravelPlanner

Ellen Shapiro
PRO

November 09, 2018
Tweet

More Decks by Ellen Shapiro

Other Decks in Technology

Transcript

  1. SIRI SHORTCUTS
    SWIFT HEROES | TORINO, ITALY | NOVEMBER 2018
    @DESIGNATEDNERD | BAKKENBAECK.COM | JUSTHUM.COM

    View Slide

  2. !

    View Slide

  3. View Slide

  4. "HEY SIRI!"

    View Slide

  5. Photo illustration via http://thetechnews.com/2016/12/07/not-only-samsung-iphone-explodes-too/

    View Slide

  6. Photo via [http://www.gizmodo.co.uk/2013/07/apparently-people-hated-the-iphone-5-the-most/

    View Slide

  7. View Slide

  8. ! " #

    View Slide

  9. View Slide

  10. View Slide

  11. View Slide

  12. MACSTORIES

    View Slide

  13. MACSTORIES

    View Slide

  14. View Slide

  15. View Slide

  16. View Slide

  17. View Slide

  18. View Slide

  19. WORKFLOW -> SHORTCUTS

    View Slide

  20. View Slide

  21. [https://twitter.com/AdamFootUK/status/1028760230304333824]

    View Slide

  22. View Slide

  23. https://twitter.com/bpmarkowitz/status/1015303601839837186

    View Slide

  24. https://twitter.com/bpmarkowitz/status/1015303601839837186

    View Slide

  25. https://twitter.com/davedelong/status/1015445465062502400

    View Slide

  26. https://twitter.com/AdrianEves07/status/1017032252629319680

    View Slide

  27. https://twitter.com/AdrianEves07/status/1017032252629319680

    View Slide

  28. https://twitter.com/AdrianEves07/status/1017032252629319680

    View Slide

  29. https://twitter.com/AdrianEves07/status/1017032252629319680

    View Slide

  30. View Slide

  31. https://twitter.com/thomaswood/status/1017428845748768769]

    View Slide

  32. View Slide

  33. WHAT ABOUT MY APP?

    View Slide

  34. View Slide

  35. View Slide

  36. 1. CREATE SHORTCUT

    View Slide

  37. 2. DONATE SHORTCUT
    TO THE SYSTEM FOR LATER USE

    View Slide

  38. View Slide

  39. 3. HANDLE SHORTCUT

    View Slide

  40. CREATING A SHORTCUT

    View Slide

  41. TEH CODEZ!
    https://github.com/designatednerd
    TravelPlanner

    View Slide

  42. EASY MODE:
    NSUserActivity

    View Slide

  43. NSUserActivity

    View Slide

  44. NSUserActivity SETUP
    let userActivity = NSUserActivity(activityType: "com.yourco.YourApp.ActivityType")
    userActivity.isEligibleForSearch = true
    userActivity.isEligibleForPrediction = true
    userActivity.title = "View \(trip.name ?? "") trip"
    userActivity.suggestedInvocationPhrase = "View \(trip.name ?? "") trip"
    userActivity.requiredUserInfoKeys = [ UserActivityInfoKey.trip.rawValue ]
    userActivity.userInfo = [ UserActivityInfoKey.trip.rawValue: trip.id ]
    userActivity.persistentIdentifier = trip.id
    viewController.userActivity = userActivity
    userActivity.becomeCurrent()

    View Slide

  45. NSUserActivity SETUP
    let userActivity = NSUserActivity(activityType: "com.yourco.YourApp.ActivityType")
    userActivity.isEligibleForSearch = true
    userActivity.isEligibleForPrediction = true
    userActivity.title = "View \(trip.name ?? "") trip"
    userActivity.suggestedInvocationPhrase = "View \(trip.name ?? "") trip"
    userActivity.requiredUserInfoKeys = [ UserActivityInfoKey.trip.rawValue ]
    userActivity.userInfo = [ UserActivityInfoKey.trip.rawValue: trip.id ]
    userActivity.persistentIdentifier = trip.id
    viewController.userActivity = userActivity
    userActivity.becomeCurrent()

    View Slide

  46. NSUserActivity SETUP
    let userActivity = NSUserActivity(activityType: "com.yourco.YourApp.ActivityType")
    userActivity.isEligibleForSearch = true
    userActivity.isEligibleForPrediction = true
    userActivity.title = "View \(trip.name ?? "") trip"
    userActivity.suggestedInvocationPhrase = "View \(trip.name ?? "") trip"
    userActivity.requiredUserInfoKeys = [ UserActivityInfoKey.trip.rawValue ]
    userActivity.userInfo = [ UserActivityInfoKey.trip.rawValue: trip.id ]
    userActivity.persistentIdentifier = trip.id
    viewController.userActivity = userActivity
    userActivity.becomeCurrent()

    View Slide

  47. NSUserActivity SETUP
    let userActivity = NSUserActivity(activityType: "com.yourco.YourApp.ActivityType")
    userActivity.isEligibleForSearch = true
    userActivity.isEligibleForPrediction = true
    userActivity.title = "View \(trip.name ?? "") trip"
    userActivity.suggestedInvocationPhrase = "View \(trip.name ?? "") trip"
    userActivity.requiredUserInfoKeys = [ UserActivityInfoKey.trip.rawValue ]
    userActivity.userInfo = [ UserActivityInfoKey.trip.rawValue: trip.id ]
    userActivity.persistentIdentifier = trip.id
    viewController.userActivity = userActivity
    userActivity.becomeCurrent()

    View Slide

  48. NSUserActivity SETUP
    let userActivity = NSUserActivity(activityType: "com.yourco.YourApp.ActivityType")
    userActivity.isEligibleForSearch = true
    userActivity.isEligibleForPrediction = true
    userActivity.title = "View \(trip.name ?? "") trip"
    userActivity.suggestedInvocationPhrase = "View \(trip.name ?? "") trip"
    userActivity.requiredUserInfoKeys = [ UserActivityInfoKey.trip.rawValue ]
    userActivity.userInfo = [ UserActivityInfoKey.trip.rawValue: trip.id ]
    userActivity.persistentIdentifier = trip.id
    viewController.userActivity = userActivity
    userActivity.becomeCurrent()

    View Slide

  49. NSUserActivity SETUP
    let userActivity = NSUserActivity(activityType: "com.yourco.YourApp.ActivityType")
    userActivity.isEligibleForSearch = true
    userActivity.isEligibleForPrediction = true
    userActivity.title = "View \(trip.name ?? "") trip"
    userActivity.suggestedInvocationPhrase = "View \(trip.name ?? "") trip"
    userActivity.requiredUserInfoKeys = [ UserActivityInfoKey.trip.rawValue ]
    userActivity.userInfo = [ UserActivityInfoKey.trip.rawValue: trip.id ]
    userActivity.persistentIdentifier = trip.id
    viewController.userActivity = userActivity
    userActivity.becomeCurrent()

    View Slide

  50. NSUserActivity SETUP
    let userActivity = NSUserActivity(activityType: "com.yourco.YourApp.ActivityType")
    userActivity.isEligibleForSearch = true
    userActivity.isEligibleForPrediction = true
    userActivity.title = "View \(trip.name ?? "") trip"
    userActivity.suggestedInvocationPhrase = "View \(trip.name ?? "") trip"
    userActivity.requiredUserInfoKeys = [ UserActivityInfoKey.trip.rawValue ]
    userActivity.userInfo = [ UserActivityInfoKey.trip.rawValue: trip.id ]
    userActivity.persistentIdentifier = trip.id
    viewController.userActivity = userActivity
    userActivity.becomeCurrent()

    View Slide

  51. NSUserActivity SETUP
    let userActivity = NSUserActivity(activityType: "com.yourco.YourApp.ActivityType")
    userActivity.isEligibleForSearch = true
    userActivity.isEligibleForPrediction = true
    userActivity.title = "View \(trip.name ?? "") trip"
    userActivity.suggestedInvocationPhrase = "View \(trip.name ?? "") trip"
    userActivity.requiredUserInfoKeys = [ UserActivityInfoKey.trip.rawValue ]
    userActivity.userInfo = [ UserActivityInfoKey.trip.rawValue: trip.id ]
    userActivity.persistentIdentifier = trip.id
    viewController.userActivity = userActivity
    userActivity.becomeCurrent()

    View Slide

  52. NSUserActivity SETUP
    let userActivity = NSUserActivity(activityType: "com.yourco.YourApp.ActivityType")
    userActivity.isEligibleForSearch = true
    userActivity.isEligibleForPrediction = true
    userActivity.title = "View \(trip.name ?? "") trip"
    userActivity.suggestedInvocationPhrase = "View \(trip.name ?? "") trip"
    userActivity.requiredUserInfoKeys = [ UserActivityInfoKey.trip.rawValue ]
    userActivity.userInfo = [ UserActivityInfoKey.trip.rawValue: trip.id ]
    userActivity.persistentIdentifier = trip.id
    viewController.userActivity = userActivity // IMPORTANT
    userActivity.becomeCurrent()

    View Slide

  53. NSUserActivity SETUP
    let userActivity = NSUserActivity(activityType: "com.yourco.YourApp.ActivityType")
    userActivity.isEligibleForSearch = true
    userActivity.isEligibleForPrediction = true
    userActivity.title = "View \(trip.name ?? "") trip"
    userActivity.suggestedInvocationPhrase = "View \(trip.name ?? "") trip"
    userActivity.requiredUserInfoKeys = [ UserActivityInfoKey.trip.rawValue ]
    userActivity.userInfo = [ UserActivityInfoKey.trip.rawValue: trip.id ]
    userActivity.persistentIdentifier = trip.id
    viewController.userActivity = userActivity // IMPORTANT
    userActivity.becomeCurrent()

    View Slide

  54. View Slide

  55. View Slide

  56. View Slide

  57. View Slide

  58. !
    SPOTLIGHT

    View Slide

  59. SPOTLIGHT SETUP
    let attributes = CSSearchableItemAttributeSet
    (itemContentType: kUTTypeContent as String)
    if let destination = trip.destination {
    attributes.contentDescription = "View details for your trip to \(destination)"
    }
    attributes.thumbnailData = UIImage(named: "trip")?.pngData()
    userActivity.contentAttributeSet = attributes

    View Slide

  60. SPOTLIGHT SETUP
    let attributes = CSSearchableItemAttributeSet
    (itemContentType: kUTTypeContent as String)
    if let destination = trip.destination {
    attributes.contentDescription = "View details for your trip to \(destination)"
    }
    attributes.thumbnailData = UIImage(named: "trip")?.pngData()
    userActivity.contentAttributeSet = attributes

    View Slide

  61. SPOTLIGHT SETUP
    let attributes = CSSearchableItemAttributeSet
    (itemContentType: kUTTypeContent as String)
    if let destination = trip.destination {
    attributes.contentDescription = "View details for your trip to \(destination)"
    }
    attributes.thumbnailData = UIImage(named: "trip")?.pngData()
    userActivity.contentAttributeSet = attributes

    View Slide

  62. SPOTLIGHT SETUP
    let attributes = CSSearchableItemAttributeSet
    (itemContentType: kUTTypeContent as String)
    if let destination = trip.destination {
    attributes.contentDescription = "View details for your trip to \(destination)"
    }
    attributes.thumbnailData = UIImage(named: "trip")?.pngData()
    userActivity.contentAttributeSet = attributes

    View Slide

  63. SPOTLIGHT SETUP
    let attributes = CSSearchableItemAttributeSet
    (itemContentType: kUTTypeContent as String)
    if let destination = trip.destination {
    attributes.contentDescription = "View details for your trip to \(destination)"
    }
    // TODO: Y U NO WORK?!
    attributes.thumbnailData = UIImage(named: "trip")?.pngData()
    userActivity.contentAttributeSet = attributes

    View Slide

  64. SPOTLIGHT SETUP
    let attributes = CSSearchableItemAttributeSet
    (itemContentType: kUTTypeContent as String)
    if let destination = trip.destination {
    attributes.contentDescription = "View details for your trip to \(destination)"
    }
    // TODO: Y U NO WORK?!
    attributes.thumbnailData = UIImage(named: "trip")?.pngData()
    userActivity.contentAttributeSet = attributes

    View Slide

  65. View Slide

  66. View Slide

  67. DON'T TRY TO
    CRAM WAY TOO MUCH REPETITIVE INFORMATION INTO THE CONTENT DESCRIPTION

    View Slide

  68. DON'T TRY TO
    CRAM WAY TOO MUCH REPETITIVE INFORMATION INTO THE CONTENT DESCRIPTION

    (LIKE THIS)

    View Slide

  69. SPOTLIGHT SETUP
    let attributes = CSSearchableItemAttributeSet
    (itemContentType: kUTTypeContent as String)
    if let destination = trip.destination {
    attributes.contentDescription = "\(destination) || \(trip.formattedDateInterval)"
    }
    attributes.thumbnailData = UIImage(named: "trip")?.pngData()
    userActivity.contentAttributeSet = attributes

    View Slide

  70. View Slide

  71. SPOTLIGHT SETUP
    let attributes = CSSearchableItemAttributeSet
    (itemContentType: kUTTypeContent as String)
    if let destination = trip.destination {
    attributes.contentDescription = """
    !
    \(destination)
    "
    \(trip.formattedTripInterval)
    """
    }
    attributes.thumbnailData = UIImage(named: "trip")?.pngData()
    userActivity.contentAttributeSet = attributes

    View Slide

  72. View Slide

  73. HANDLING
    SHORTCUT SELECTION

    View Slide

  74. UIApplicationDelegate

    View Slide

  75. UIApplicationDelegate
    SETUP
    func application(_ application: UIApplication,
    continue userActivity: NSUserActivity,
    restorationHandler:
    @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
    guard userActivity.activityType == "com.yourco.YourApp.ActivityType" else {
    return false
    }
    let handlingVC = // Omitted for length
    restorationHandler(handlingVC)
    return true
    }

    View Slide

  76. UIApplicationDelegate
    SETUP
    func application(_ application: UIApplication,
    continue userActivity: NSUserActivity,
    restorationHandler:
    @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
    guard userActivity.activityType == "com.yourco.YourApp.ActivityType" else {
    return false
    }
    let handlingVC = // Omitted for length
    restorationHandler(handlingVC)
    return true
    }

    View Slide

  77. UIApplicationDelegate
    SETUP
    func application(_ application: UIApplication,
    continue userActivity: NSUserActivity,
    restorationHandler:
    @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
    guard userActivity.activityType == "com.yourco.YourApp.ActivityType" else {
    return false
    }
    let handlingVC = // Omitted for length
    restorationHandler(handlingVC)
    return true
    }

    View Slide

  78. UIApplicationDelegate
    SETUP
    func application(_ application: UIApplication,
    continue userActivity: NSUserActivity,
    restorationHandler:
    @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
    guard userActivity.activityType == "com.yourco.YourApp.ActivityType" else {
    return false
    }
    let handlingVC = // Omitted for length
    restorationHandler(handlingVC)
    return true
    }

    View Slide

  79. View Slide

  80. HARD MODE:
    Intents FRAMEWORK

    View Slide

  81. View Slide

  82. View Slide

  83. INIntent
    +
    INInteraction

    View Slide

  84. View Slide

  85. View Slide

  86. View Slide

  87. View Slide

  88. View Slide

  89. View Slide

  90. View Slide

  91. View Slide

  92. View Slide

  93. View Slide

  94. View Slide

  95. View Slide

  96. View Slide

  97. View Slide

  98. View Slide

  99. DONATING AN INTERACTION
    let arrivalIntent = ArrivalTimeIntent()
    arrivalIntent.origin = plan.originName
    arrivalIntent.destination = plan.destinationName
    arrivalIntent.suggestedInvocationPhrase = "\(plan.destinationName) arrival"
    let arrivalInteraction = INInteraction(intent: arrivalIntent,
    response: nil)
    arrivalInteraction.donate { error in
    if let error = error {
    debugPrint("Error donating arrival intent: \(error)")
    }
    }

    View Slide

  100. DONATING AN INTERACTION
    let arrivalIntent = ArrivalTimeIntent()
    arrivalIntent.origin = plan.originName
    arrivalIntent.destination = plan.destinationName
    arrivalIntent.suggestedInvocationPhrase = "\(plan.destinationName) arrival"
    let arrivalInteraction = INInteraction(intent: arrivalIntent,
    response: nil)
    arrivalInteraction.donate { error in
    if let error = error {
    debugPrint("Error donating arrival intent: \(error)")
    }
    }

    View Slide

  101. DONATING AN INTERACTION
    let arrivalIntent = ArrivalTimeIntent()
    arrivalIntent.origin = plan.originName
    arrivalIntent.destination = plan.destinationName
    arrivalIntent.suggestedInvocationPhrase = "\(plan.destinationName) arrival"
    let arrivalInteraction = INInteraction(intent: arrivalIntent,
    response: nil)
    arrivalInteraction.donate { error in
    if let error = error {
    debugPrint("Error donating arrival intent: \(error)")
    }
    }

    View Slide

  102. View Slide

  103. View Slide

  104. View Slide

  105. View Slide

  106. DONATING AN INTERACTION
    let arrivalIntent = ArrivalTimeIntent()
    arrivalIntent.origin = plan.originName
    arrivalIntent.destination = plan.destinationName
    arrivalIntent.suggestedInvocationPhrase = "\(plan.destinationName) arrival"
    let arrivalInteraction = INInteraction(intent: arrivalIntent,
    response: nil)
    arrivalInteraction.donate { error in
    if let error = error {
    debugPrint("Error donating arrival intent: \(error)")
    }
    }

    View Slide

  107. DONATING AN INTERACTION
    let arrivalIntent = ArrivalTimeIntent()
    arrivalIntent.origin = plan.originName
    arrivalIntent.destination = plan.destinationName
    arrivalIntent.suggestedInvocationPhrase = "\(plan.destinationName) arrival"
    let arrivalInteraction = INInteraction(intent: arrivalIntent,
    response: nil)
    arrivalInteraction.donate { error in
    if let error = error {
    debugPrint("Error donating arrival intent: \(error)")
    }
    }

    View Slide

  108. AppDelegate INTENT SETUP
    func application(_ application: UIApplication,
    continue userActivity: NSUserActivity,
    restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
    if let arrivalIntent = intent as? ArrivalTimeIntent {
    guard let plan = Plan.fromArrivalIntent(arrivalIntent,
    in: CoreDataManager.shared.mainContext) else {
    return false
    }
    coordinator.viewPlan(plan)
    return true
    }
    // Else, go through the rest of method we saw earlier
    }

    View Slide

  109. AppDelegate INTENT SETUP
    func application(_ application: UIApplication,
    continue userActivity: NSUserActivity,
    restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
    if let arrivalIntent = userActivity.interaction?.intent as? ArrivalTimeIntent {
    guard let plan = Plan.fromArrivalIntent(arrivalIntent,
    in: CoreDataManager.shared.mainContext) else {
    return false
    }
    coordinator.viewPlan(plan)
    return true
    }
    // Else, go through the rest of method we saw earlier
    }

    View Slide

  110. AppDelegate INTENT SETUP
    func application(_ application: UIApplication,
    continue userActivity: NSUserActivity,
    restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
    if let arrivalIntent = userActivity.interaction?.intent as? ArrivalTimeIntent {
    guard let plan = Plan.fromArrivalIntent(arrivalIntent,
    in: CoreDataManager.shared.mainContext) else {
    return false
    }
    coordinator.viewPlan(plan)
    return true
    }
    // Else, go through the rest of method we saw earlier
    }

    View Slide

  111. AppDelegate INTENT SETUP
    func application(_ application: UIApplication,
    continue userActivity: NSUserActivity,
    restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
    if let arrivalIntent = userActivity.interaction?.intent as? ArrivalTimeIntent {
    guard let plan = Plan.fromArrivalIntent(arrivalIntent,
    in: CoreDataManager.shared.mainContext) else {
    return false
    }
    coordinator.viewPlan(plan)
    return true
    }
    // Else, go through the rest of method we saw earlier
    }

    View Slide

  112. AppDelegate INTENT SETUP
    func application(_ application: UIApplication,
    continue userActivity: NSUserActivity,
    restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
    if let arrivalIntent = userActivity.interaction?.intent as? ArrivalTimeIntent {
    guard let plan = Plan.fromArrivalIntent(arrivalIntent,
    in: CoreDataManager.shared.mainContext) else {
    return false
    }
    coordinator.viewPlan(plan)
    return true
    }
    // Else, go through the rest of method we saw earlier
    }

    View Slide

  113. EXPERT MODE:
    RESPONSES + INTENT EXTENSION

    View Slide

  114. View Slide

  115. INTENT HANDLER SETUP
    public class ArrivalTimeIntentHandler: NSObject, ArrivalTimeIntentHandling {
    // Optional!
    public func confirm(intent: ArrivalTimeIntent,
    completion: @escaping (ArrivalTimeIntentResponse) -> Void) {
    // Figure out if the thing can be done
    }
    public func handle(intent: ArrivalTimeIntent,
    completion: @escaping (ArrivalTimeIntentResponse) -> Void) {
    // Do the thing!
    completion(.success)
    }
    }

    View Slide

  116. INTENT HANDLER SETUP
    public class ArrivalTimeIntentHandler: NSObject, ArrivalTimeIntentHandling {
    // Optional!
    public func confirm(intent: ArrivalTimeIntent,
    completion: @escaping (ArrivalTimeIntentResponse) -> Void) {
    // Figure out if the thing can be done
    }
    public func handle(intent: ArrivalTimeIntent,
    completion: @escaping (ArrivalTimeIntentResponse) -> Void) {
    // Do the thing!
    completion(.success)
    }
    }

    View Slide

  117. INTENT HANDLER SETUP
    public class ArrivalTimeIntentHandler: NSObject, ArrivalTimeIntentHandling {
    // Optional!
    public func confirm(intent: ArrivalTimeIntent,
    completion: @escaping (ArrivalTimeIntentResponse) -> Void) {
    // Figure out if the thing can be done
    }
    public func handle(intent: ArrivalTimeIntent,
    completion: @escaping (ArrivalTimeIntentResponse) -> Void) {
    // Do the thing!
    completion(.success)
    }
    }

    View Slide

  118. View Slide

  119. View Slide

  120. View Slide

  121. INTENT HANDLER SETUP
    public class ArrivalTimeIntentHandler: NSObject, ArrivalTimeIntentHandling {
    public func handle(intent: ArrivalTimeIntent,
    completion: @escaping (ArrivalTimeIntentResponse) -> Void) {
    guard let plan = Plan.fromArrivalIntent(intent,
    in: CoreDataManager.shared.mainContext) else {
    if let destination = intent.destination {
    completion(.failureNoFuturePlansToDestination(destination))
    } else {
    completion(ArrivalTimeIntentResponse(code: .failureNoDestination,
    userActivity: nil))
    }
    return
    }
    completion(.success(destination: plan.destinationName,
    method: plan.methodName,
    origin: plan.originName,
    time: plan.formattedEndTime,
    date: .formattedEndDate))
    }
    }

    View Slide

  122. INTENT HANDLER SETUP
    public class ArrivalTimeIntentHandler: NSObject, ArrivalTimeIntentHandling {
    public func handle(intent: ArrivalTimeIntent,
    completion: @escaping (ArrivalTimeIntentResponse) -> Void) {
    guard let plan = Plan.fromArrivalIntent(intent,
    in: CoreDataManager.shared.mainContext) else {
    if let destination = intent.destination {
    completion(.failureNoFuturePlansToDestination(destination))
    } else {
    completion(ArrivalTimeIntentResponse(code: .failureNoDestination,
    userActivity: nil))
    }
    return
    }
    completion(plan.toArrivalIntentResponse)
    }
    }

    View Slide

  123. View Slide

  124. INTENT HANDLER SETUP
    public class ArrivalTimeIntentHandler: NSObject, ArrivalTimeIntentHandling {
    public func handle(intent: ArrivalTimeIntent,
    completion: @escaping (ArrivalTimeIntentResponse) -> Void) {
    guard let plan = Plan.fromArrivalIntent(intent,
    in: CoreDataManager.shared.mainContext) else {
    if let destination = intent.destination {
    completion(.failureNoFuturePlansToDestination(destination))
    } else {
    completion(ArrivalTimeIntentResponse(code: .failureNoDestination,
    userActivity: nil))
    }
    return
    }
    completion(plan.toArrivalIntentResponse)
    }
    }

    View Slide

  125. INTENT HANDLER SETUP
    public class ArrivalTimeIntentHandler: NSObject, ArrivalTimeIntentHandling {
    public func handle(intent: ArrivalTimeIntent,
    completion: @escaping (ArrivalTimeIntentResponse) -> Void) {
    guard let plan = Plan.fromArrivalIntent(intent,
    in: CoreDataManager.shared.mainContext) else {
    if let destination = intent.destination {
    completion(.failureNoFuturePlansToDestination(destination))
    } else {
    completion(ArrivalTimeIntentResponse(code: .failureNoDestination,
    userActivity: nil))
    }
    return
    }
    completion(plan.toArrivalIntentResponse)
    }
    }

    View Slide

  126. APP GROUPS AND
    SHARED CONTAINERS

    View Slide

  127. THINGS TO MOVE TO A CONTAINER
    > Core Data
    > Keychain
    > User Defaults
    > Data Caching

    View Slide

  128. SETUP INSTRUCTIONS

    View Slide

  129. SETUP INSTRUCTIONS
    ¯\_(ϑ)_/¯

    View Slide

  130. View Slide

  131. View Slide

  132. GALAXY BRAIN MODE:
    IntentsUI EXTENSION

    View Slide

  133. View Slide

  134. View Slide

  135. INTENT UI SETUP
    func configureView(for parameters: Set,
    of interaction: INInteraction,
    interactiveBehavior: INUIInteractiveBehavior,
    context: INUIHostedViewContext,
    completion: @escaping (Bool, Set, CGSize) -> Void) {
    completion(true, parameters, self.desiredSize)
    }
    var desiredSize: CGSize {
    return self.extensionContext!.hostedViewMaximumAllowedSize
    }

    View Slide

  136. INTENT UI SETUP
    func configureView(for parameters: Set,
    of interaction: INInteraction,
    interactiveBehavior: INUIInteractiveBehavior,
    context: INUIHostedViewContext,
    completion: @escaping (Bool, Set, CGSize) -> Void) {
    completion(true, parameters, self.desiredSize)
    }
    var desiredSize: CGSize {
    return self.extensionContext!.hostedViewMaximumAllowedSize
    }

    View Slide

  137. INTENT UI SETUP
    func configureView(for parameters: Set,
    of interaction: INInteraction,
    interactiveBehavior: INUIInteractiveBehavior,
    context: INUIHostedViewContext,
    completion: @escaping (Bool, Set, CGSize) -> Void) {
    completion(true, parameters, self.desiredSize)
    }
    var desiredSize: CGSize {
    return self.extensionContext!.hostedViewMaximumAllowedSize
    }

    View Slide

  138. INTENT UI SETUP
    func configureView(for parameters: Set,
    of interaction: INInteraction,
    interactiveBehavior: INUIInteractiveBehavior,
    context: INUIHostedViewContext,
    completion: @escaping (Bool, Set, CGSize) -> Void) {
    completion(true, parameters, self.desiredSize)
    }
    var desiredSize: CGSize {
    return self.extensionContext!.hostedViewMaximumAllowedSize
    }

    View Slide

  139. INTENT UI SETUP
    func configureView(for parameters: Set,
    of interaction: INInteraction,
    interactiveBehavior: INUIInteractiveBehavior,
    context: INUIHostedViewContext,
    completion: @escaping (Bool, Set, CGSize) -> Void) {
    completion(true, parameters, self.desiredSize)
    }
    var desiredSize: CGSize {
    return self.extensionContext!.hostedViewMaximumAllowedSize
    }

    View Slide

  140. INTENT UI SETUP
    func configureView(for parameters: Set,
    of interaction: INInteraction,
    interactiveBehavior: INUIInteractiveBehavior,
    context: INUIHostedViewContext,
    completion: @escaping (Bool, Set, CGSize) -> Void) {
    completion(true, parameters, self.desiredSize)
    }
    var desiredSize: CGSize {
    return self.extensionContext!.hostedViewMaximumAllowedSize
    }

    View Slide

  141. INTENT UI SETUP
    func configureView(for parameters: Set,
    of interaction: INInteraction,
    interactiveBehavior: INUIInteractiveBehavior,
    context: INUIHostedViewContext,
    completion: @escaping (Bool, Set, CGSize) -> Void) {
    completion(true, parameters, self.desiredSize)
    }
    var desiredSize: CGSize {
    return self.extensionContext!.hostedViewMaximumAllowedSize
    }

    View Slide

  142. INTENT UI SETUP
    func configureView(for parameters: Set,
    of interaction: INInteraction,
    interactiveBehavior: INUIInteractiveBehavior,
    context: INUIHostedViewContext,
    completion: @escaping (Bool, Set, CGSize) -> Void) {
    completion(true, parameters, self.desiredSize)
    }
    var desiredSize: CGSize {
    return self.extensionContext!.hostedViewMaximumAllowedSize
    }

    View Slide

  143. View Slide

  144. func configureView(for parameters: Set,
    of interaction: INInteraction,
    interactiveBehavior: INUIInteractiveBehavior,
    context: INUIHostedViewContext,
    completion: @escaping (Bool, Set, CGSize) -> Void) {
    var plan: Plan? = nil
    let moc = CoreDataManager.shared.mainContext
    if let departureIntent = interaction.intent as? DepartureTimeIntent {
    plan = Plan.fromDepartureIntent(departureIntent, in: moc)
    } else if let arrivalIntent = interaction.intent as? ArrivalTimeIntent {
    plan = Plan.fromArrivalIntent(arrivalIntent, in: moc)
    }
    guard let retrievedPlan = plan else {
    completion(false, parameters, .zero)
    return
    }
    let coordinator = EmbeddedPlanCoordinator(plan: retrievedPlan)
    coordinator.configureIn(viewController: self)
    completion(true, parameters, self.desiredSize)
    }
    var desiredSize: CGSize {
    return self.extensionContext!.hostedViewMaximumAllowedSize
    }

    View Slide

  145. View Slide

  146. func configureView(for parameters: Set,
    of interaction: INInteraction,
    interactiveBehavior: INUIInteractiveBehavior,
    context: INUIHostedViewContext,
    completion: @escaping (Bool, Set, CGSize) -> Void) {
    var plan: Plan? = nil
    let moc = CoreDataManager.shared.mainContext
    if let departureIntent = interaction.intent as? DepartureTimeIntent {
    plan = Plan.fromDepartureIntent(departureIntent, in: moc)
    } else if let arrivalIntent = interaction.intent as? ArrivalTimeIntent {
    plan = Plan.fromArrivalIntent(arrivalIntent, in: moc)
    }
    guard let retrievedPlan = plan else {
    completion(false, parameters, .zero)
    return
    }
    let coordinator = EmbeddedPlanCoordinator(plan: retrievedPlan)
    coordinator.configureIn(viewController: self)
    let size = CGSize(width: self.view.frame.width,
    height: coordinator.contentHeight)
    completion(true, parameters, size)
    }

    View Slide

  147. View Slide

  148. View Slide

  149. View Slide

  150. View Slide

  151. View Slide

  152. func configureView(for parameters: Set,
    of interaction: INInteraction,
    interactiveBehavior: INUIInteractiveBehavior,
    context: INUIHostedViewContext,
    completion: @escaping (Bool, Set, CGSize) -> Void) {
    var plan: Plan? = nil
    let moc = CoreDataManager.shared.mainContext
    if let departureIntent = interaction.intent as? DepartureTimeIntent {
    plan = Plan.fromDepartureIntent(departureIntent, in: moc)
    } else if let arrivalIntent = interaction.intent as? ArrivalTimeIntent {
    plan = Plan.fromArrivalIntent(arrivalIntent, in: moc)
    }
    guard let retrievedPlan = plan else {
    completion(false, parameters, .zero)
    return
    }
    let coordinator = EmbeddedPlanCoordinator(plan: retrievedPlan)
    coordinator.configureIn(viewController: self)
    let size = CGSize(width: self.view.frame.width,
    height: coordinator.contentHeight + 15)
    completion(true, parameters, size)
    }

    View Slide

  153. View Slide

  154. View Slide

  155. View Slide

  156. View Slide

  157. View Slide

  158. View Slide

  159. View Slide

  160. View Slide

  161. !
    CARROT MODE:
    LOL CLIPBOARD WORKAROUNDS

    View Slide

  162. View Slide

  163. View Slide

  164. View Slide

  165. View Slide

  166. View Slide

  167. View Slide

  168. View Slide

  169. View Slide

  170. View Slide

  171. UX FOR VOICE

    View Slide

  172. VoiceX

    View Slide

  173. VoiceX
    (TOO ELON MUSK)

    View Slide

  174. VUX

    View Slide

  175. VUX
    (SOUNDS TOO MUCH LIKE VOX)

    View Slide

  176. VX

    View Slide

  177. VX
    (IS NERVE GAS)

    View Slide

  178. UX FOR VOICE

    View Slide

  179. KEEP SUGGESTED INVOCATION PHRASES
    SHORT AND SIMPLE

    View Slide

  180. HEY SIRI, WHEN IS MY NEXT FLIGHT?

    View Slide

  181. View Slide

  182. HEY SIRI, WHEN IS MY NEXT FLIGHT?

    View Slide

  183. WHEN IS MY NEXT FLIGHT?

    View Slide

  184. WHEN IS MY NEXT FLIGHT?

    View Slide

  185. WHEN IS MY NEXT FLIGHT?

    View Slide

  186. NEXT FLIGHT

    View Slide

  187. OBLIGATORY SUMMARY SLIDE

    View Slide

  188. OBLIGATORY SUMMARY SLIDE
    > Shortcuts are a great tool for automation

    View Slide

  189. OBLIGATORY SUMMARY SLIDE
    > Shortcuts are a great tool for automation
    > your shortcuts are a bit more limited

    View Slide

  190. OBLIGATORY SUMMARY SLIDE
    > Shortcuts are a great tool for automation
    > your shortcuts are a bit more limited
    > Use NSUserActivity for basic shortcuts

    View Slide

  191. OBLIGATORY SUMMARY SLIDE
    > Shortcuts are a great tool for automation
    > your shortcuts are a bit more limited
    > Use NSUserActivity for basic shortcuts
    > Use Custom Intents for complex shortcuts

    View Slide

  192. OBLIGATORY SUMMARY SLIDE
    > Shortcuts are a great tool for automation
    > your shortcuts are a bit more limited
    > Use NSUserActivity for basic shortcuts
    > Use Custom Intents for complex shortcuts
    > Keep titles / invocation phrases short

    View Slide

  193. OBLIGATORY SUMMARY SLIDE
    > Shortcuts are a great tool for automation
    > your shortcuts are a bit more limited
    > Use NSUserActivity for basic shortcuts
    > Use Custom Intents for complex shortcuts
    > Keep titles / invocation phrases short
    > Custom responses handle errors clearly

    View Slide

  194. OBLIGATORY SUMMARY SLIDE
    > Shortcuts are a great tool for automation
    > your shortcuts are a bit more limited
    > Use NSUserActivity for basic shortcuts
    > Use Custom Intents for complex shortcuts
    > Keep titles / invocation phrases short
    > Custom responses handle errors clearly
    > Responses + Intent UI = users

    View Slide

  195. LINKS!
    > Siri Shortcuts ebook by Mohammad Azam
    https://gumroad.com/l/eHKUm/
    SIRIshortcuts
    > A Beginner's Guide to developing custom
    intent siri shortcuts for iOS 12 by Peter
    Minarik
    https://medium.com/@pietropizzi/
    a-beginners-guide-to-developing-
    custom-intent-siri-shortcuts-for-
    ios-12-a3627b7011af

    View Slide

  196. WWDC VIDEOS!
    > Session 211: Introduction to Siri Shortcuts
    https://developer.apple.com/
    videos/play/wwdc2018/211/
    > Session 214: Building for Voice with Siri
    Shortcuts
    https://developer.apple.com/
    videos/play/wwdc2018/214/

    View Slide

  197. MOAR WWDC VIDEOS!
    > Session 217: Siri Shortcuts On The Watch Face
    https://developer.apple.com/
    videos/play/wwdc2018/217/
    > Session 404: New Localization Workflows in
    Xcode 10
    https://developer.apple.com/
    videos/play/wwdc2018/404/

    View Slide

  198. MACSTORIES LINKS!
    > Shortcuts: A New Vision for Siri and iOS
    Automation
    https://www.macstories.net/
    stories/shortcuts-a-new-vision-
    for-siri-and-ios-automation/
    > Original Workflow Review
    https://www.macstories.net/
    reviews/workflow-review-
    integrated-automation-for-ios-8/

    View Slide

  199. EXCAVATED LINKS!
    > Original Workflow Teaser video
    https://www.youtube.com/watch?
    v=fSh6Q0F4d9Q

    View Slide