225 Extending Your Apps with SiriKit 05 FINAL · 2016-07-08 · Session 225 Extending Your Apps...

Preview:

Citation preview

© 2016 Apple Inc. All rights reserved. Redistribution or public display not permitted without written permission from Apple.

App Frameworks #WWDC16

Session 225

Extending Your Apps with SiriKit

Vineet Khosla SiriKit EngineeringDiana Huang SiriKit EngineeringScott Andrus SiriKit Engineering

Adding SiriKit

Intents Extension AppIntents UI Extension

Adding SiriKit

Intents Extension AppIntents UI Extension

Confirm HandleResolve

Agenda

Preparing to adopt SiriKit

Agenda

Preparing to adopt SiriKitAdding your first Intents extension

Agenda

Preparing to adopt SiriKitAdding your first Intents extensionProviding a user interface in Siri

UnicornChat

Preparing to Adopt SiriKit

Preparing to Adopt SiriKit

Preparing to Adopt SiriKit

Embedded frameworks

Preparing to Adopt SiriKit

Embedded frameworksUnit tests

Preparing to Adopt SiriKit

Embedded frameworksUnit testsArchitecting your extensions

Embedded frameworksPreparing to Adopt SiriKit

Embedded frameworksPreparing to Adopt SiriKit

Networking

Embedded frameworksPreparing to Adopt SiriKit

NetworkingData model

Embedded frameworksPreparing to Adopt SiriKit

NetworkingData modelDecision-making logic

Embedded frameworksPreparing to Adopt SiriKit

NetworkingData modelDecision-making logicUser interfaces

Embedded frameworksPreparing to Adopt SiriKit

NetworkingData modelDecision-making logicUser interfaces

Embedded frameworksPreparing to Adopt SiriKit

App Extension Best Practices WWDC 2015

NetworkingData modelDecision-making logicUser interfaces

Unit testsPreparing to Adopt SiriKit

Unit testsPreparing to Adopt SiriKit

Mock intents

Unit testsPreparing to Adopt SiriKit

Mock intentsMake sure your app responds appropriately

Architecting your extensionsPreparing to Adopt SiriKit

SendMessageIntent

StartAudioCallIntent

StartVideoCallIntent

Architecting your extensionsPreparing to Adopt SiriKit

SendMessageIntent

StartAudioCallIntent

StartVideoCallIntent

Architecting your extensionsPreparing to Adopt SiriKit

SendMessageIntent

StartAudioCallIntent

StartVideoCallIntent

Architecting your extensionsPreparing to Adopt SiriKit

SendMessageIntent

StartAudioCallIntent

StartVideoCallIntent

Adding Your First Intents Extension

Diana Huang SiriKit Engineering

Getting Started

Getting Started

Add extension target

Getting Started

Add extension targetConfigure Info.plist

Getting Started

Add extension targetConfigure Info.plistModify principal class

Adding an extension target Intents Extension

Adding an extension target Intents Extension

Adding an extension target Intents Extension

Info.plistIntents Extension

Info.plistIntents Extension

Info.plist

IntentsSupported IntentsRestrictedWhileLocked

NSExtension

NSExtensionAttributes

Info.plistIntents Extension

Info.plist

IntentsSupported IntentsRestrictedWhileLocked

NSExtension

NSExtensionAttributes

IntentsSupported

Info.plistIntents Extension

Info.plist

IntentsSupported IntentsRestrictedWhileLocked

NSExtension

NSExtensionAttributes

IntentsRestrictedWhileLocked

Principal classIntents Extension

Principal classIntents Extension

Subclass of INExtension

Principal classIntents Extension

Subclass of INExtensionINIntentHandlerProviding

Principal classIntents Extension

Subclass of INExtensionINIntentHandlerProviding• handlerForIntent

Principal classIntents Extension

Subclass of INExtensionINIntentHandlerProviding• handlerForIntent• handler class must conform to specific intent handling protocol

DemoCreating my first Intents extension

ResolveResolve, Confirm, Handle

ResolveResolve, Confirm, Handle

Validate and clarify parameters

ResolveResolve, Confirm, Handle

Validate and clarify parametersImplement it if you might need Siri to help ask users

ResolveResolve, Confirm, Handle

ResolveResolve, Confirm, Handle

recipients

ResolveResolve, Confirm, Handle

Contact search recipients

ResolveResolve, Confirm, Handle

Contact search• Exactly one match

recipients

ResolveResolve, Confirm, Handle

Contact search• Exactly one match• Two or more matches

recipients

ResolveResolve, Confirm, Handle

Contact search• Exactly one match• Two or more matches• No match

recipients

ResolveResolve, Confirm, Handle

Contact search• Exactly one match• Two or more matches• No match

recipientsResolve

ResolveResolve, Confirm, Handle

recipientsResolve

ResolveResolve, Confirm, Handle

Contact search recipientsResolve

ResolveResolve, Confirm, Handle

Contact search recipientsResolve content

ResolveResolve, Confirm, Handle

Contact searchNeed a value to proceed

recipientsResolve content

ConfirmResolve, Confirm, Handle

recipientsResolve content

ConfirmResolve, Confirm, Handle

Confirm

recipientsResolve content

ConfirmResolve, Confirm, Handle

Dry run• Tell Siri how it went

Confirm

recipientsResolve content

ConfirmResolve, Confirm, Handle

Dry run• Tell Siri how it went

Confirm authenticated?

recipientsResolve content

HandleResolve, Confirm, Handle

Just handle it!• Again, tell Siri how it went

Confirm authenticated?

Handle

recipientsResolve content

DemoFilling in my app logic

Resume state in your appNSUserActivity

Resume state in your appNSUserActivity

Siri creates one by default

Resume state in your appNSUserActivity

Siri creates one by default• ActivityType is intent class name

Resume state in your appNSUserActivity

Siri creates one by default• ActivityType is intent class name

You can provide one to pass custom data

Resume state in your appNSUserActivity

Siri creates one by default• ActivityType is intent class name

You can provide one to pass custom dataINInteraction

DemoProviding my own NSUserActivity

User-Specific Vocabulary

User-Specific Vocabulary

Phrases unique to your app and user

User-Specific Vocabulary

Phrases unique to your app and user• e.g. contact names

User-Specific Vocabulary

Phrases unique to your app and user• e.g. contact names

Help Siri understand what users mean

User-Specific Vocabulary

Phrases unique to your app and user• e.g. contact names

Help Siri understand what users meanINVocabulary API call from main app

User-Specific Vocabulary

Phrases unique to your app and user• e.g. contact names

Help Siri understand what users meanINVocabulary API call from main app• NOT your extension

// User-Specific Vocabulary - UnicornChat

class UCAddressBookManager {

// This method is called whenever there is a contact change

func updateSiriKnowledgeOfContacts() {

// provide the updated list of favorites' unicorn names to Siri

var unicornNames = OrderedSet(array: self.sortedFavoriteUnicornNames)

INVocabulary.shared().setVocabularyStrings(unicornNames, of:

INVocabularyStringType.contactName)

}

}

// User-Specific Vocabulary - UnicornChat

class UCAddressBookManager {

// This method is called whenever there is a contact change

func updateSiriKnowledgeOfContacts() {

// provide the updated list of favorites' unicorn names to Siri

var unicornNames = OrderedSet(array: self.sortedFavoriteUnicornNames)

INVocabulary.shared().setVocabularyStrings(unicornNames, of:

INVocabularyStringType.contactName)

}

}

// User-Specific Vocabulary - UnicornChat

class UCAddressBookManager {

// This method is called whenever there is a contact change

func updateSiriKnowledgeOfContacts() {

// provide the updated list of favorites' unicorn names to Siri

var unicornNames = OrderedSet(array: self.sortedFavoriteUnicornNames)

INVocabulary.shared().setVocabularyStrings(unicornNames, of:

INVocabularyStringType.contactName)

}

}

// User-Specific Vocabulary - UnicornChat

class UCAddressBookManager {

// This method is called whenever there is a contact change

func updateSiriKnowledgeOfContacts() {

// provide the updated list of favorites' unicorn names to Siri

DispatchQueue(label: "UCSiriVocabulary").asynchronously(execute: { () -> Void in

var unicornNames = OrderedSet(array: self.sortedFavoriteUnicornNames)

INVocabulary.shared().setVocabularyStrings(unicornNames, of:

INVocabularyStringType.contactName)

})

}

}

// User-Specific Vocabulary - UnicornChat

class UCAddressBookManager {

// This method is called whenever there is a contact change

func updateSiriKnowledgeOfContacts() {

// provide the updated list of favorites' unicorn names to Siri

DispatchQueue(label: "UCSiriVocabulary").asynchronously(execute: { () -> Void in

var unicornNames = OrderedSet(array: self.sortedFavoriteUnicornNames)

INVocabulary.shared().setVocabularyStrings(unicornNames, of:

INVocabularyStringType.contactName)

})

}

}

// User-Specific Vocabulary - UnicornChat

class UCAddressBookManager {

// This method is called whenever there is a contact change

func updateSiriKnowledgeOfContacts() {

// provide the updated list of favorites' unicorn names to Siri

DispatchQueue(label: "UCSiriVocabulary").asynchronously(execute: { () -> Void in

var unicornNames = OrderedSet(array: self.sortedFavoriteUnicornNames)

INVocabulary.shared().setVocabularyStrings(unicornNames, of:

INVocabularyStringType.contactName)

})

}

}

Providing a User Interface with SiriKit

Scott Andrus SiriKit Engineering

UI Extensions Increase Your App’s Impact

UI Extensions Increase Your App’s Impact

Your view alongside Siri

UI Extensions Increase Your App’s Impact

Your view alongside SiriExperiences unique to your application

UI Extensions Increase Your App’s Impact

Your view alongside SiriExperiences unique to your applicationUser-specific customization

UI Extensions Increase Your App’s Impact

Your view alongside SiriExperiences unique to your applicationUser-specific customizationInformation Siri might not otherwise show

UI Extensions Increase Your App’s Impact

Your view alongside SiriExperiences unique to your applicationUser-specific customizationInformation Siri might not otherwise show

How to get startedAdd UI Extension Target to Xcode

Add Intents UI Extension target

How to get startedAdd UI Extension Target to Xcode

Add Intents UI Extension targetEmbed in application

How to get startedAdd UI Extension Target to Xcode

Info.plist

NSExtension

NSExtensionAttributes

Info.plistIntents UI Extension

IntentsSupported

Info.plist

NSExtension

NSExtensionAttributes

Info.plistIntents UI Extension

IntentsSupported

Siri

Siri

configure(with interaction:...)

UI extension

Siri

configure(with interaction:...)

UI extension

Siri UIViewController : INUIHostedViewControlling

configure(with interaction:...)

UI extensionINInteractionSiri UIViewController :

INUIHostedViewControllingconfigure(with interaction:...)

INIntentHandlingStatus

INIntentResponse

INIntent

Breaking it downINInteraction

INInteraction

INIntentHandlingStatus

INIntentResponse

INIntent

Breaking it downINInteraction

The handled (or to-be-handled) INIntent

INInteraction

INIntentHandlingStatus

INIntentResponse

INIntent

Breaking it downINInteraction

The handled (or to-be-handled) INIntentThe provided INIntentResponse

INInteraction

INIntentHandlingStatus

INIntentResponse

INIntent

Breaking it downINInteraction

The handled (or to-be-handled) INIntentThe provided INIntentResponseINIntentHandlingStatus INInteraction

Implementing Your View Controller

Implementing Your View Controller

Principal class

Implementing Your View Controller

Principal classSubclass of UIViewController

Implementing Your View Controller

Principal classSubclass of UIViewControllerConfigure with interaction

Implementing Your View Controller

Principal classSubclass of UIViewControllerConfigure with interactionProvided view context

Implementing Your View Controller

Principal classSubclass of UIViewControllerConfigure with interactionProvided view context

Implementing Your View Controller

Principal classSubclass of UIViewControllerConfigure with interactionProvided view context

Implementing Your View Controller

Principal classSubclass of UIViewControllerConfigure with interactionProvided view contextDesired size in the completion

DemoBuilding a SiriKit UI extension

Siri Gives You Override Control

Siri Gives You Override Control

Implement INUIHostedViewSiriProviding

Siri Gives You Override Control

Implement INUIHostedViewSiriProvidingProperties for displaying messages and maps

Siri Gives You Override Control

Implement INUIHostedViewSiriProvidingProperties for displaying messages and mapsOpt-in to displaying a particular interface

Siri Gives You Override Control

Implement INUIHostedViewSiriProvidingProperties for displaying messages and mapsOpt-in to displaying a particular interfaceSiri will accommodate your view’s content

}

func configure(with interaction: INInteraction!, context: INUIHostedViewContext,

completion: ((CGSize) -> Void)!) {

// Configure your view

completion(self.extensionContext!.hostedViewMaximumAllowedSize)

}

class IntentViewController: UIViewController, INUIHostedViewControlling,

INUIHostedViewSiriProviding {

var displaysMessage: Bool {

return true

}

}

func configure(with interaction: INInteraction!, context: INUIHostedViewContext,

completion: ((CGSize) -> Void)!) {

// Configure your view

completion(self.extensionContext!.hostedViewMaximumAllowedSize)

}

class IntentViewController: UIViewController, INUIHostedViewControlling,

INUIHostedViewSiriProviding {

var displaysMessage: Bool {

return true

}

}

func configure(with interaction: INInteraction!, context: INUIHostedViewContext,

completion: ((CGSize) -> Void)!) {

// Configure your view

completion(self.extensionContext!.hostedViewMaximumAllowedSize)

}

class IntentViewController: UIViewController, INUIHostedViewControlling,

INUIHostedViewSiriProviding {

var displaysMessage: Bool {

return true

}

}

func configure(with interaction: INInteraction!, context: INUIHostedViewContext,

completion: ((CGSize) -> Void)!) {

// Configure your view

completion(self.extensionContext!.hostedViewMaximumAllowedSize)

}

class IntentViewController: UIViewController, INUIHostedViewControlling,

DemoTelling Siri about our interface

Considerations

Considerations

Be memory conscious

Considerations

Be memory consciousMinimum and maximum view sizes

Considerations

Be memory consciousMinimum and maximum view sizesFlexible and adaptive layout patterns

Summary

Summary

Prepare to adopt SiriKit

Summary

Prepare to adopt SiriKitAdd your first Intents extension

Summary

Prepare to adopt SiriKitAdd your first Intents extensionProvide a user interface in Siri

More Information

https://developer.apple.com/wwdc16/225

Related Sessions

Introducing SiriKit Presidio Wednesday 5:00PM

App Extension Best Practices WWDC 2015

Labs

SiriKit Lab Frameworks Lab C Thursday 3:00PM

SiriKit Lab Frameworks Lab B Friday 9:00AM

Recommended