learn about ios10 siri kit

27
Say Hello to Siri ! Snehal Patil – iOS Developer @ Yahoo

Upload: snehal-patil

Post on 14-Apr-2017

467 views

Category:

Engineering


0 download

TRANSCRIPT

Page 1: Learn about iOS10 Siri Kit

Say Hello to Siri !

Snehal Patil – iOS Developer @ Yahoo

Page 2: Learn about iOS10 Siri Kit
Page 3: Learn about iOS10 Siri Kit

Only Supported Domains ! •  VoIP calling •  Messaging •  Payments •  Photo •  Workouts •  Ride booking •  CarPlay (automotive vendors only) •  Restaurant reservations (requires

additional support from Apple)

So before you go and start thinking about all the different potential use cases for your app, keep in mind that Apple has only opened support for these six domains.

!

Page 4: Learn about iOS10 Siri Kit

2 new Frameworks Siri Kit was introduced in WWDC 2016, giving users the ability to control your app’s behavior using their voice.

Intents framework - communication between your app and the system.

Intents UI framework - presenting a custom interface when one of your tasks is performed.

Page 5: Learn about iOS10 Siri Kit

Siri Workflow 1.  First, Siri takes the audio of the user's Speech and converts it into text. 2.  Next, the text is converted into an Intent, a structured representation of the

user's request. 3.  Based on the Intent, Siri will take Action to perform the user's request. 4.  Finally, Siri will present Responses (both visual and verbal) to the user based

on the Action taken.

Speech Intent Action Response

Page 6: Learn about iOS10 Siri Kit

Siri + App Workflow 1.  Vocabulary - This is how the app tells Siri the words it needs to know to interact with it. 2.  App Logic - These are the actions and responses that the app will take based on given Intents. 3.  User Interface - This is the optional, custom user interface that the app can give its responses in.

Speech Intent Action Response

Vocabulary App Logic User Interface

Page 7: Learn about iOS10 Siri Kit

Intent Object - Messaging Domain The structured Intent will contain the following information:

Domain: Messages Intent: sendMessage Recipient: John Content: lets go!

INSendMessageIntentResponseCode - unspecified, ready, Inprogress, success, failure, failureRequiringAppLaunch, failureMessageServiceNotAvailable NSUserActivity

INSendMessageIntent INSendMessageIntentResponse

Page 8: Learn about iOS10 Siri Kit

The Intent Lifecycle

1.  The app must Resolve every parameter on an event. As a result, the app will call Resolve multiple times (once

per each parameter), and sometimes multiple times on the same parameter until the app and the user agree on what is being requested.

2.  The app must Confirm that it can handle the requested Intent and tell Siri about the expected outcome. 3.  Finally, the app must Handle the Intent and perform the steps to achieve the requested outcome.

Page 9: Learn about iOS10 Siri Kit

The Intent Extension

●  The Intents Extension is responsible for handling the main interactions between the app and Siri ●  Implements resolve, confirms and handle results ●  Support one or more intents - choose as per your apps requirements ●  Runs in the background while Siri is in foreground ●  Security can be handled by - restricting access while device is locked locked and by asking

permission - for ex, dont allow user to send payments when app is locked.

Page 10: Learn about iOS10 Siri Kit

Intent Methods - Messaging Domain

Page 11: Learn about iOS10 Siri Kit

Resolve func resolveRecipients(forSendMessage intent: INSendMessageIntent, with completion: ([INPersonResolutionResult]) -> Swift.Void) { } Resolve response

Success(with:) Your app matched the user's request

ConfirmationRequired(with:) Siri makes sure about users request

Disambiguation(with:) Your app needs the user to select from a list of people provide options to choose from

Page 12: Learn about iOS10 Siri Kit

Confirm func confirm(sendMessage intent: INSendMessageIntent, completion: @escaping (INSendMessageIntentResponse) -> Void) { let userActivity = NSUserActivity(activityType: NSStringFromClass(INSendMessageIntent.self)) let response = INSendMessageIntentResponse(code: .ready, userActivity: userActivity) completion(response) }

•  Tell Siri the expected result of an intent using intent response •  Siri prompts for confirmation using NSUserActivity

Page 13: Learn about iOS10 Siri Kit

Handle func handle(sendMessage intent: INSendMessageIntent, completion: @escaping (INSendMessageIntentResponse) -> Void) { let userActivity = NSUserActivity(activityType: NSStringFromClass(INSendMessageIntent.self)) let response = INSendMessageIntentResponse(code: .success, userActivity: userActivity) completion(response) }

•  Perform the requested action •  Provide as much info about the result as possible •  Provide response in few seconds, otherwise use inprogress intent (for ex, network call)

Page 14: Learn about iOS10 Siri Kit

Intent UI Extension •  Bring your apps interface into siri ( for ex. Brand, visual

identity)

•  Provide a UIViewcontroller - which can be customized

•  Completely Optional

•  Displayed alongside siri content

•  Not interactive - you can’t put "controls" in your UI intent interface.

Page 15: Learn about iOS10 Siri Kit

Creating Intent Extension

Page 16: Learn about iOS10 Siri Kit

Extensions

Page 17: Learn about iOS10 Siri Kit

Siri Entitlement

Page 18: Learn about iOS10 Siri Kit

Configuration plist

NSExtension

NSExtensionAttributes

IntentsSupported

IntentsRestrictedWhile- Locked (optional)

Page 19: Learn about iOS10 Siri Kit

Requesting Authorization in plist Include the NSSiriUsageDescription key in your iOS app’s Info.plist file.

Page 20: Learn about iOS10 Siri Kit

Requesting Siri Authorization in Your iOS App

INPreferences.requestSiriAuthorization() { (status) in print("New status: \(status)") }

Page 21: Learn about iOS10 Siri Kit

Structuring Your App’s Services

Implement your core services in a private shared

framework : A private shared framework lets you define your core services in one code module and link the code dynamically into your iOS app and your Intents extension. Using a framework minimizes the size of both executables and ensures that both use the same code.

Use a shared container to store common

resources. Put relevant images and data files into a shared container so that they can also be accessed by your Intents extension. You can enable shared container support in the Capabilities tab of your iOS app and Intents extension targets.

Page 22: Learn about iOS10 Siri Kit

Specifying Custom Vocabulary - INVocabulary object

•  Defining custom vocabulary helps Siri understand commands used in conjunction with your app, which improves the user experience.

•  Choose terms that could be misunderstood by someone not familiar with your app.

•  Do not register terms that are easily understood, ex. “My Photo Album” or “My Workout”.

•  Focus on terms whose literal meaning differs from your app’s usage of those terms. •  The most important terms should always be first in the NSOrderedSet object that you

create. •  To register terms that are specific to a single user, use the INVocabulary object.

let workoutNames = self.sortedWorkoutNames() let vocabulary = INVocabular.shared() vocabulary.setVocabularyStrings(workoutNames, of: .workoutActivityName)

Page 23: Learn about iOS10 Siri Kit

Global Vocabulary file - AppIntentVocabulary.plist

Page 24: Learn about iOS10 Siri Kit

Demo

Page 25: Learn about iOS10 Siri Kit

Limitation •  Only support few domains. Out of the 2 million apps in the App Store, how many fall under the

support of the six categories? This is the primary downside of the system Apple devised.

•  If you are very excited to add speech recognition into your app which might not fall into supported Siri kit domain - Try Speech Recognition Framework -- https://realm.io/news/tryswift-marc-brown-say-it-aint-so-implementing-speech-recognition/?utm_campaign=This%2BWeek%2Bin%2BSwift&utm_medium=email&utm_source=This_Week_in_Swift_103

Page 26: Learn about iOS10 Siri Kit

Example Code •  Unicorn Chat - https://developer.apple.com/library/prerelease/content/samplecode/UnicornChat/

Listings/SiriExtension_UCSendMessageIntentHandler_swift.html

Page 27: Learn about iOS10 Siri Kit

Thank you !