Search

SiriKit Part 1: Hey Siri, How Do I Get Started?

John Daub

5 min read

Sep 18, 2017

iOS

SiriKit Part 1: Hey Siri, How Do I Get Started?

Siri is Apple’s intelligent personal assistant, and it allows you to use your voice to interact with your iOS, watchOS, tvOS and macOS devices. Already used by millions, this technology will only continue to grow; in fact, MarketsAndMarkets predicts that the speech and voice recognition market will be valued at $18.3 billion by 2023. And in an effort to continue to thrive in this market, Apple has made it easier for developers to integrate their apps with Siri using SiriKit.

This series will explore SiriKit, why it is important and how you can use it to expose your app’s functionality through Siri. We’ll walk through the basics of SiriKit and how to add support to your iOS app, take a deepdive into Intents and then address final touches that make for a good Siri user experience.

What is SiriKit?

Siri strives to feel natural to users by providing a conversational interface; instead of rigid commands, you just talk to Siri. While this makes using Siri easy for the user, it can be quite complicated for developers. Fortunately, Apple alleviates this complexity by handling the conversational aspects—you just provide the functionality. To provide the functionality, developers use SiriKit.

SiriKit is Apple’s toolkit for exposing your app’s functionality through Siri. It was introduced in iOS 10, and despite Siri’s ubiquitous presence across all Apple platforms, as of this writing SiriKit is only available on iOS and watchOS. When someone speaks to Siri, Siri turns the speech into text, turns the text into what the user wants to do (discovers their intent), which leads to an action and results in a response. Working with the user’s intent is the heart of SiriKit.

Understanding Intent

Siri is limited in what it can do, functioning only within known Domains. A Domain is a category of things Siri knows about, like making VoIP calls, messaging, making payments, working with lists and notes and helping with your workouts. Within each Domain is a series of Intents, which are actions Siri can perform. For example, within the payments Domain there are Intents to send payments, transfer money and pay bills. In the ride booking Domain, there are Intents to request a ride and get the ride status. When considering SiriKit adoption, look at the Domains and their Intents to see which ones make sense for your app.

An Intent often has parameters: when sending a message, to whom it is addressed; when making a reservation, what restaurant and for how many people. Consequently, implementing an Intent has you performing three steps:

  1. Resolve the parameters: help Siri understand what the user provided, including the ability to ask the user for clarification, confirmation or additional information.
  2. Confirm all-the-things: last chance to ensure all the Intent parameters are as they should be, and that your app can handle the user’s request (e.g. a service is online and available).
  3. Handle it: do the thing!

Of these three phases, what and how you do them depends upon the specific Intent; be sure to read headers and Apple’s documentation. Part 2 of this series will examine the three phases in-depth. But first things first: let’s add an Intents Extension to our app.

Adding an Intents Extension

Because interaction with Siri occurs outside of your app, your app’s SiriKit functionality is implemented as an app extension—specifically an Intents App Extension. Let’s create one!

Enabling the Siri App Capability in Xcode

Enabling the Siri app capability in Xcode.

  1. Open your project in Xcode.
  2. Select your app target, and the Capabilities tab.
  3. Enable the Siri capability.

That will add the Siri service to your App ID, and the Siri entitlement to your project.

Adding an Intents Extension Target to Your Xcode Project

Next, create an Intents Extension target in your project.

Adding an Intents Extension target to your Xcode project.

  1. Open your project in Xcode.
  2. From the menubar select: “File” > “New” > “Target…”
  3. Select “Intents Extension.” Note that it is not a “Siri Extension,” and you don’t want an “Intents UI Extension,” as that’s something related but different, and click Next.
  4. Choose the options for the new target and click Finish.

Editing the Intents Extension’s Info.plist

In order to let the system know what Intents the app can handle, edit the extension’s Info.plist.

Editing the Intents Extension's Info.plist.

  1. Open the Intents Extension’s Info.plist
  2. Disclose the NSExtension item. If the Info.plist doesn’t contain one, add one of type dictionary.
  3. Disclose the NSExtensionAttributes item. If there isn’t one, add one of type dictionary.
  4. Edit the IntentsSupported extension attribute, adding one of type array, if needed. Each entry should be a string of the class name of the Intent you support—one entry for every supported Intent. For example, if you support INSendMessageIntent, there should be an entry of “INSendMessageIntent”.
  5. If you have any Intents that require an unlocked device, list those under the IntentsRestrictedWhileLocked extension attribute.
  6. The NSExtensionPointIdentifier extension attribute should have a value of “com.apple.intents-service”.
  7. The NSExtensionPrincipalClass extension attribute should have the correct value via project stationery. More information about this will be discussed later.

Build & Run

That’s it! Your app now has the essential elements to work with Siri. Let’s try it out! And yes, you can work with Siri within the iOS Simulator.

  1. Ensure your Intents Extension target/scheme is selected.
  2. Run.
  3. When Xcode prompts you for the app to run, select Siri.

Running the Intents Extension, selecting Siri as the app to run.

When the Siri waveform interface appears, you can begin your conversation with Siri. Say: “Send a message using My Great App”, and watch your Intents Extension be invoked. If you set breakpoints in the IntentHandler.swift file, you can watch the extension go through the resolve, confirm and handle phases. Notice that depending on what you say to Siri, some parameters may be resolved multiple times.

Of course, as developers, we tend to do the same thing again and again while we develop. If every time you run your Intents Extension, you have to select the Siri app to run and speak your phrase, it can become tiresome. Thankfully, Xcode provides a nice runtime convenience:

  1. Edit your Intents Extension’s scheme.
  2. Select the “Run” panel.
  3. Select the “Info” tab.

That one weird trick to make Siri development easier: editing the scheme for the Siri Intent Query.

If you enter a phase for the “Siri Intent Query,” Xcode will automatically run Siri and use your text as the invoking phrase. If you leave this field blank, the Xcode will prompt you upon running.

Congratulations! You’ve successfully added an Intents Extension to your application, and can begin extending your app’s capabilities with Siri.

The full source code for this (and the entire SiriKit series) can be found here.

Next Up

Of course, this doesn’t do anything useful or engaging with your app. In Part 2, we’ll do something useful and explore three key notions in working with Siri: resolve, confirm and handle.

And if you’re having trouble implementing SiriKit or other features into your iOS or watchOS app, Big Nerd Ranch is happy to help. Get in touch to see how our team can build a Siri-enabled app for you, or implement this and other new features into an existing app.

John Daub

Author Big Nerd Ranch

John “Hsoi” Daub is a Director of Technology (and former Principal Architect) at Big Nerd Ranch. He’s been an avid computer nerd since childhood, with a special love for Apple platforms. Helping people through their journey is what brings him the greatest satisfaction. If he’s not at the computer, he’s probably at the gym lifting things up and putting them down.

Speak with a Nerd

Schedule a call today! Our team of Nerds are ready to help

Let's Talk

Related Posts

We are ready to discuss your needs.

Not applicable? Click here to schedule a call.

Stay in Touch WITH Big Nerd Ranch News