Given by Alexsander Akers at Swift Alps on 29 Nov. 2018
SiriKit (Apple Documentation)
- Messaging
- Lists and Notes
- Workouts
- Payments
- VoIP Calling
- Visual Codes
- Photos
- Ride Booking
- Car Commands*
- CarPlay*
- Restaurant Reservations*
* Requires private entitlement from Apple
- Defined in your app through Intents.intentdefinition file
- Used to repeat a specific action that the user has already performed, or that the app thinks is relevant
- These intents support parameters, but are "baked into" the intent at the time the shortcut is added
- For example, you cannot prompt for additional information through Siri, but you can continue a flow in your app
An NSUserActivity
is a snapshot of what the user is doing in your app at a moment in time. These activities allow users to hand off their tasks between devices, to search for previously viewed content (e.g. map items), and to allow the system to suggest relevant data from user-initiated activities in your app.
Donating Shortcuts (Apple Documentation)
- Assign NSUserActivity instances to your view controllers (or call the activity's
becomeCurrent()
method). - Set
isEligibleForPrediction
on the activity totrue
. - Optionally set
suggestedInvocationPhrase
on the activity to show the user with a specific (localized!) as a prompt. - Implement the
UIApplicationDelegate
methodapplication(_:continue:restorationHandler:)
- Use
INShortcut
to create a shortcut. Then create aINUIAddVoiceShortcutViewController
view controller with that shortcut to allow the user to record a invocation phrase for this shortcut.
- Create a new Intents Extension target in your app.
- Add the intent type to your extension's Info.plist file under
NSExtension > IntentsSupported
orNSExtension > IntentsRestrictedWhileLocked
- Modify the template IntentHandler.swift class to initialize handler objects for
INIntent
types.- The
INCreateTaskListIntentHandling
protocol matches theINCreateTaskListIntent
intent so the stringINCreateTaskListIntent
would go in the Info.plist array.
- The
- Create a
CreateTaskListIntentHandler
class that conforms to theINCreateTaskListIntentHandling
protocol and implement the methods in that protocol to resolve details of the intent, confirm the response, and handle the intent of the user. - Repeat these steps (starting with 2) for each INIntent type you want to support
- Create a new Intents Extension target in your app.
- Create a SiriKit Intent Definition File-type file in your app's shared framework.
- Include this file in your app, your app's shared framework, and your app's Intents extension. If your app has an IntentsUI extension, include this file there as well.
- Make sure that the Intent Classes option is only selected for your app's shared framework target(s).
- Click on the
+
button to create a new custom intent or to customize an existing system intent. - Select an appropriate Category and specify the Title and Description for your intent.
- Follow the steps above to mark your extension as supporting your custom intent as well as to implement the custom intent handler.
MVCTodo is a sample project by Dave DeLong (modified to remove some of the initial shared framework overhead) that we can use as a basis on which to implement the Siri Lists domain. Follow the steps for Task B for each list- and task-related INIntent
type found on the Lists and Notes domain page.
- SiriKit Documentation
- Apple Sample Code: Soup Chef
- Talk to me! I am also a resource. Raise your hand to get my attention, and I will try to help.