Hey Siri, make my app AMAZING

Siri Shortcuts was one of the hottest new additions to iOS 12 last year. Its ease of use and its numerous possibilities make it a low hanging fruit when thinking about possible new features for your app. They will allow your users to perform certain actions through voice commands and let you decide how your app would handle them.

If you were already making use of NSUserActivity for indexing elements in your app, creating a shortcut is really simple. All you need to do is to add:

BAAM! Now after you perform any of your NSUserActivity you can go to Settings > Your app > Siri & Search > Shortcuts and select your shortcut to record a phrase and start using Siri to perform tasks in your app.

Cool, right? User friendly? Hmm not that much. To achieve that you will need to add a Siri button inside your app whenever that NSUserActivity is used. It’s as simple as:

There is a limitation though; if your NSUserActivity represents multiple instances of the same type you won’t be able to differentiate between them.

In our case, opening the current user’s profile worked perfectly since it’s unique but it wouldn’t work if we want to perform a room search, since it’s parametrised depending on where you want to search.

Custom Intents come to the rescue!

In order to overcome the limitations previously described, we can make use of Custom Intents, they can be parametrised and is therefore able to represent multiple elements of the same type. We can make use of Custom Intents in just three steps and we will show it to you by implementing Siri in our room search:

First we need to create a SiriKit Intent Definition File, in that file we create a new Intent called RoomSearch and add the search term parameter as a String. This will generate a file we shouldn’t modify.

Then we create an extension of our already existing SearchModel to add a property of type RoomSearch and give its properties the appropriate values.

Now in our Siri button we just need to remove the code that linked it with the NSUserActivity and add the shortcut instead:

That’s it! Our Siri button is now connected to our intent, and the users will now be able to record/edit a phrase to call it. Now it’s a matter of handling the shortcut in our app delegate once is invoked.

What Siri brings to Badi

By implementing the above, we just need to call Siri and this will happen:

If you like what we do at Badi, you can have a look into our current job openings page, or if you have any questions feel free to contact me @tonik_12.