Class

INUIAddVoiceShortcutViewController

A view controller that guides the user through the steps for adding a shortcut to Siri.

Overview

When the user performs an action such as placing an order for tomato soup, the app should provide the option to add the action to Siri as a shortcut. To present this option in your app, use INUIAddVoiceShortcutButton to display an Add to Siri button. Using this button makes your app consistent with other apps that support Siri Shortcuts.

After creating the button, assign its action to a method that displays INUIAddVoiceShortcutViewController. This controller steps the user through the process of adding the shortcut to Siri.

To receive notifications of events from the view controller, set the delegate to an object that conforms to the INUIAddVoiceShortcutViewControllerDelegate protocol.

Listing 1

Add an Add to Siri button to a view and let the user record an invocation phrase

// Add an "Add to Siri" button to a view.
func addSiriButton(to view: UIView) {
    let button = INUIAddVoiceShortcutButton(style: .blackOutline)
    button.translatesAutoresizingMaskIntoConstraints = false

    view.addSubview(button)
    view.centerXAnchor.constraint(equalTo: button.centerXAnchor).isActive = true
    view.centerYAnchor.constraint(equalTo: button.centerYAnchor).isActive = true

    button.addTarget(self, action: #selector(addToSiri(_:)), for: .touchUpInside)
}

// Present the Add Shortcut view controller after the
// user taps the "Add to Siri" button.
@objc
func addToSiri(_ sender: Any) {
    if let shortcut = INShortcut(intent: orderSoupOfTheDayIntent) {
        let viewController = INUIAddVoiceShortcutViewController(shortcut: shortcut)
        viewController.modalPresentationStyle = .formSheet
        viewController.delegate = self // Object conforming to `INUIAddVoiceShortcutViewControllerDelegate`.
        present(viewController, animated: true, completion: nil)
    }
}

Topics

Creating an Add Shortcut View Controller

init(shortcut: INShortcut)

Creates a view controller with a shortcut the user can add to Siri.

Handling View Controller Events

var delegate: INUIAddVoiceShortcutViewControllerDelegate?

The object that retrieves notifications from the view controller.

protocol INUIAddVoiceShortcutViewControllerDelegate

The protocol an object implements to receive notifications from the view controller adding a shortcut to Siri.

See Also

Shortcut Editors

class INUIEditVoiceShortcutViewController

A view controller that lets the user edit or remove an existing shortcut.

Beta

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software