IntentsUI inside SiriKit provides a new UIButton subclass with default user interface that can present an INUIAddVoiceShortcutViewController. This controller guides the user through the process of adding the shortcut to Siri instead of adding the shortcut to Shortcuts app and to device settings’ Siri section. First of all you have to import IntentsUI in your ViewController.

This button has 4 possibile styles that should be passed as parameters in init method:

Different styles

Note: INUIAddVoiceShortcutButton with style initializer comes with frame zero so if you init it programmatically remember to set button.translatesAutoresizingMaskIntoConstraints = false

Next step: create an INShortcut and set it into the button property. Touch up inside on INUIAddVoiceShortcutButton will automatically invoke actions on this shortcut.

A shortcut can be created with both an INIntent and an NSUserActivity. If you choose to work with INIntent remember that the initializer is failable.

Learn more about custom INIntent in the talk linked in the first paragraph or in this page of Apple Documentation.

Now it’s time to setup the delegate. INUIAddVoiceShortcutButtonDelegate protocol implementation will inform your view controller when it’s time to present a request view controller.

In this example I’m just presenting addVoiceShortcutViewController or editVoiceShortcutViewController without any other action, but you can check which button has called the delegate method or do the action that you prefer (I suggest to use those methods to track on your analytics service these actions).

Note: there’s no “edit button” so will be the button that will choose which view controller to present

It’s not over, we have one last point missing: INUIAddVoiceShortcutViewController and INUIEditVoiceShortcutViewController must have their own delegates because like many other system ViewControllers (i.e. mail sharing) they does not dismiss programmatically on cancel or success.

We have to handle two more delegates, but we can just discard the VC in any case like I’m doing in this example or like before use those methods to do any collateral action. Is interesting to trace also this events to understand better what your user is doing with Siri Shortcut.

Method signature are very talking about the action that the user has taken and please note that I’ve added delegate to previous methods: