Contents

getAllVoiceShortcuts(completion:)

Retrieves all shortcuts added to Siri for your app.

Declaration

func getAllVoiceShortcuts(completion completionHandler: @escaping  @Sendable ([INVoiceShortcut]?, (any Error)?) -> Void)
func allVoiceShortcuts() async throws -> [INVoiceShortcut]

Parameters

  • completionHandler:

    The block invoked on a background thread after the system retrieves the list of shortcuts. This block has no return value and takes the following parameters:

    voiceShortcuts

    An array of Invoiceshortcut objects. This parameter is nil when an error occurs.

    error

    An Nserror object if a problem occurred retrieving the shortcuts; otherwise, nil.

Discussion

Let users know when an action they perform in your app has an associated shortcut. For example, a user has created a shortcut in the soup-ordering app Soup Chef that allows them to place an order for tomato soup by speaking the phrase “Soup time.” The app shows the phrase in the user’s order history, reminding them that the shortcut exists and of the phrase to speak in order to invoke the shortcut in Siri.

[Image]

The app uses the getAllVoiceShortcuts(completion:) method to retrieve the list of shortcuts associated to the app. The list contains shortcuts added to Siri with INUIAddVoiceShortcutViewController and those added by the user in the Settings app.

The listing below retrieves shortcuts associated with the Soup Chef app.

public func updateVoiceShortcuts(completion: (() -> Void)?) {
    INVoiceShortcutCenter.shared.getAllVoiceShortcuts { (voiceShortcutsFromCenter, error) in
        if let voiceShortcutsFromCenter = voiceShortcutsFromCenter {
            self.voiceShortcuts = voiceShortcutsFromCenter
        } else {
            if let error = error as NSError? {
                os_log("Failed to fetch voice shortcuts with error: %@", log: OSLog.default, type: .error, error)
            }
        }

        if let completion = completion {
            completion()
        }
    }
}

See Also

Related Documentation

Getting Shortcuts Added to Siri