Part 2: Adding and responding to intents
Specify which intents your app supports.
1. In Xcode, select the Info.plist
file of your Intents extension.
2. Expand the NSExtension
and NSExtensionAttributes
keys to reveal the IntentsSupported
andIntentsRestrictedWhileLocked
keys.
3. In the IntentsSupported
key, add a String item for each intent that the extension handles. Set the value of each item to the class name of the intent. (For now, we are going to use the messages intent)
You can view more intents here
Resolving and Handling Intents
- Open up IntentHandler.swift
2. Observe the different functions automatically generated. This is where the logic for your Siri intent is.
Custom Vocabulary
If your app has custom vocabulary, such as terms that Siri might not inherently understand should register these terms. Ex: a ride booking app that refers to a specific vehicle type as a “Vroom” could define that term and provide examples of how it might be used.
There are two ways to define your app’s custom vocabulary:
-
To register terms that are specific to a single user, use the
INVocabulary
object. -
To register terms common to all users of your app, add a global vocabulary file to your iOS app. They must belong to the category of either “Ride Options” or “Workout names”
To register terms specific to a single user:
Creating a Global Vocabulary File
- Select New –> File
- In iOS –> Resources, select the Property List file Type –> Click Next
- Set the name of the file to “AppIntentVocabulary.plist” –> Click Create
-
Select the
AppIntentVocabulary.plist
file in your project.
5. Add two keys under the Root element.
- Set the name of the first key to
ParameterVocabularies
. This key defines your app’s custom terms and the intent parameters that apply - Set the name of the second key to
IntentPhrases
. This key contains examples for invoking your services
Creating an Intents UI Extension
Since we checked off UI Extension when we first added the Intent, we do not have to do anything in terms of adding new files.
- Open up IntentsViewController.swift
- Under the “configure” function, you can customize your view here <configure image>
- In MainInterface.storyboard, you can add UI Elements and hook them up to outlets to customize the appearance
Once you run your app, you will see the updated UI
Disclosure: This is a brief, straight to the point tutorial. The object is not to go in depth, but to give a quick overview of how to get SiriKit up and running. For more information visit developer.apple.com