Adding vocabularies through a .plist file

You already learned that Siri understands when a user wants to do something with your application, even if your user uses your app name as a verb. However, your app name might not be the only thing that's specific to your app. Let's see how this works for a workout app.

If, for example, a user were to tell Siri, Hey Siri, start an Ultimate Run using RunPotato, Siri would be able to figure out what RunPotato is since it's the app that is expected to handle the intent. What it won't be able to understand instantly is what it means to start an Ultimate Run. This is where a custom vocabulary entry in a .plist makes a lot of sense.

The .plist that contains the vocabulary should be provided by the application itself; the corresponding extension is not able to do this. You can add a vocabulary of app-specific words, like the workout name above, by adding an extra .plist file to the app. To add a new .plist file, add a new file to your app target and select the Property List file type under the Resource header as shown in the following screenshot:

The file you create must be named AppIntentVocabulary. This file contains all of the information about an app's custom vocabulary. The vocabulary .plist is pretty specific and verbose. This is important because its purpose is to provide a window into the vocabulary your app uses. When you created the AppIntentVocabulary.plist file, Xcode added a dictionary at the top level of the file. All custom vocabulary should be added to that dictionary.

To implement the example phrase shown earlier, you need a Parameter Vocabularies array. This array will contain Parameter Vocabulary items that specify the vocabulary the app uses for workout names. The first item that needs to be defined is a Parameter Names array. For the workout app, it would contain a single entry: INStartWorkoutIntent.workoutName. In addition to the parameter names, a Parameter Vocabulary dictionary must also be added to the entry in the Parameter Vocabularies array.

The Parameter Vocabulary dictionary has keys for the item identifier, synonyms for this identifier, a pronunciation, and even an example phrase. This is all very verbose, but it provides Siri with all of the information it needs to resolve user input for your app. The following screenshot shows an example of the entry that would be needed to make sure Siri understands what an Ultimate Run workout is:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.97.189