Add and configure an Intents app extension in your Xcode project.
Interactions with SiriKit occur through your Intents app extension, which you deliver inside your iOS or watchOS app bundle. The Intents app extension handles most interactions with SiriKit. However, your app needs to be aware of those interactions and in some cases may have an active role in making them happen.
Configuring your Xcode project requires several steps. In addition to adding an Intents app extension target to your project, you must make some minor changes to your app as well.
Enable the Siri Capability
Enabling the Siri capability adds a set of entitlements to your app. The App Store requires the presence of these entitlements for any iOS app or watchOS app containing an Intents extension.
Open your app project in Xcode.
In the project settings, select the appropriate target. For iOS, select your iOS app target. For watchOS, select your WatchKit Extension target.
Select the Capabilities tab.
Enable the Siri capability.
Add an Intents App Extension to Your Project
Adding an Intents app extension target provides the initial files you need to build your Intents extension and configures your Xcode project to build that extension and include it in your app’s bundle.
Open your existing app project in Xcode.
Choose File > New > Target.
Select Intents extension from the Application Extension group of the iOS or watchOS platform.
Specify the name of your extension and configure the language and other options.
For an iOS app, enable the Include UI Extension option if you plan to customize portions of the Siri interface.
Specify the Intents that Your Extension Supports
After adding your Intents extension target to your project, configure the default
Info file provided by Xcode to specify which intents you support. SiriKit uses the information in your extension’s
Info file to determine which intents to route to your extension.
In Xcode, select the
Infofile of your Intents app extension.
NSExtensionkeys to reveal the
Intentskey (iOS and watchOS) and the
Intentskey (iOS only).
Restricted While Locked
Intentskey, add a String item for each intent that your extension handles. Set the value of each item to the class name of the intent.
Intentskey, add a String item for each intent for which you require the device to be unlocked. Set the value of each item to the class name of the intent.
Restricted While Locked
Inclusion of the
Intents key is optional in iOS. You use it to augment the list of intents that require an unlocked device. Some intents, such as those involving financial transactions, always require the user’s device to be unlocked. For those intents, Siri automatically asks the user to unlock the device, regardless of whether you include it under the
Intents key. In watchOS, all intents require the device to be unlocked.
When a user’s utterance is ambiguous enough that it resolves to multiple intents, SiriKit uses the order of the intents in the
Intents key to determine which intent to send to your app. Organize your list of intents by putting the most relevant ones first in the array. Prioritizing your intents is especially important when your Intents extension supports multiple domains with similar semantics. For example, an app that supports both calling and messaging intents might choose to prioritize sending a message over initiating a call.
Some intents may require additional configuration steps for your Xcode project or your app. For example, when implementing a ride booking app, Maps expects you to provide a GeoJSON file that describes the coverage area for your service. See the reference documentation for information about any special requirements.
Test Your Intents App Extension
Xcode supports launching your Intents app extension directly from your Xcode project and debugging it while it runs in the simulator or on a device. To run and debug your Intents extension:
Select the build scheme for your Intents extension. Xcode automatically creates a build scheme for you when creating your Intents extension target.
Select the target (simulator or device) on which to run your code.
Select Product > Run to begin your debugging session.
When prompted by Xcode, select Siri or Maps as the main app to run. Xcode builds your app and extension, installs them on the devices, and launches the app you selected.
When installing your extension for the first time, Siri may not immediately recognize your app extension and you may need to wait several minutes before you can issue any relevant commands. Similarly, when updating your extension’s
Info file, you may need to wait several minutes before Siri recognizes any changes.