Andrew Graham

Demystifying Siri, Part 4: Suggestions

In Part 1 of this series we were resigned to the fact that a user wasn’t immediately able to make use of Siri to solve numbers games using NumberRace. Our user has to go through the rigmarole of creating a shortcut and adding a spoken phrase before Siri is even aware of this functionality. You’ll recall that this is a problem with custom intents; Siri’s inbuilt system intents, such as booking a ride or playing music, does not suffer from this problem. Is there anything we can do to reduce the friction in creating a shortcut?

Let us suppose that our hypothetical user is a fan of TV game show Countdown and uses our app to solve numbers games while it is broadcast. Wouldn’t it be great if we could automatically provide a prompt at that time every weekday? Fortunately we can, using suggestions.

Creating intent suggestions

You’ll recall that in Part 1 we discussed that it is possible, as a developer, to notify Siri that a user has carried out a particular activity in your app. Siri is then able to make predictions about when an activity is likely to be used and then present it as a suggestion on the lock screen or the search screen of the user’s phone at the appropriate time.

We’ll create some suggestions by re-opening our Intents.intentdefinition file. Select the SolveGame custom intent and scroll down to Suggestions.

We’ll create three types of suggestion:

Firstly, ensure that Intent is eligible for Siri Suggestions is checked. Then we’ll add our suggestions - each with our different parameter combinations. For each suggestion type, click on the + sign below the Supported Combinations box. Enter the parameter combinations and give a summary for each. When all is done we should end up with something resembling the screenshot below.

Donating intents

Next, we need to inform Siri whenever the solver is used in our app. In order to do this we need to ensure a donation occurs whenever the user taps on the ‘Solve’ button. Let’s get this done by creating a function:

func donateSolveGameIntent() {
    if #available(iOS 12.0, *) {
        let intent = SolveGameIntent()
        let interaction = INInteraction(intent: intent, response: nil)
        interaction.donate(completion: nil)

If we have iOS 12 and above, we can create a SolveGameIntent, populate it with a target and initial numbers (although here we haven’t done that) and donate it to Siri.

When the user presses ‘Solve’ in the solver, we ensure that this function is run.

@IBAction func solveScreen() {
    // ...code to run the solver

It’s important that, when donating an intent to Siri, the intent data in the donation matches a parameter combination in the intent definition. If a matching parameter combination is not found then a suggestion will not be made.

We’ve left our intent data blank because it’s very unlikely that a user going to run the solver with the same numbers and target each time. We could have populated our intent data with a target and initial numbers, but there’s no benefit in doing so. But if there was some regular pattern to our intent data Siri can recognise it and come up with a suggestion tailored to our needs, using the most relevant parameter combination we defined in our intent definition file.

For example, let’s suppose we use a banking app to manually make a regular payment to the milkman every week. The payee stays the same but the amount varies each time. The app donates that intent with the payee and amount data. Siri is able to recognise that the payee is the same, discard the amount, and display a generic “Pay the milkman” suggestion on our phone’s lock screen.

Let’s see if that works…

Donating intents in action

Fortunately we don’t have to wait an age while Siri collates all our new intent donations. We can make a change to our settings to see suggestions as they happen. Open the Settings app, then select Developer. Scroll down to Display Recent Shortcuts and ensure that this setting is enabled. Also ensure that Display Donations on Lock Screen is enabled.

The Developer settings screen
The Developer settings screen

Open NumberRace, then our solver, then click on Solve. The next time our lock screen appears then we have a suggestion! This suggestion also appears in our shortcuts app, where we can attach a custom phrase. Or we can navigate to the Siri & Search section of the Settings app to do the same thing.

A Siri suggestion - Solve a numbers game - on a lock screen
A Siri Suggestion

Having a conversation

We’ve travelled quite far on our journey, but we still haven’t reached our destination - for Siri to ask us for numbers and to read out a solution. We’ll do this in Part 5. Will we then finally reach our goal? (Spoiler alert: this is a six, maybe seven, part series, so no.)