Home » SiriKit Tutorial – Right to the Point (Part 2)

SiriKit Tutorial – Right to the Point (Part 2)

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

addintentspreview

Resolving and Handling Intents

  1. 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:

registervocabinvc

Creating a Global Vocabulary File

  1. Select New –> File
  2. In iOS –> Resources, select the Property List file Type –> Click Next
  3. Set the name of the file to “AppIntentVocabulary.plist” –> Click Create
  4. 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

registervocabpreview

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.

  1. Open up IntentsViewController.swift
     configureintent
  2. Under the “configure” function, you can customize your view here <configure image>
  3. In MainInterface.storyboard, you can add UI Elements and hook them up to outlets to customize the appearance

storyboardintent

Once you run your app, you will see the updated UI

siriintentdemophone

 

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