Offering Actions in the Shortcuts App
Suggest shortcuts users may want to add to Siri or combine with other actions in their own shortcuts.
Overview
When the user performs an action in your app, donate a shortcut that accelerates user access to the action. Siri shows these donated interactions to the user in places such as Spotlight search and the Lock Screen.
However, sometimes there are actions in your app the user hasn’t performed that might be of interest to them. For example, perhaps your soup-ordering app features a special soup every day. The user has never ordered the daily soup special, but they might be interested in the option to add a soup-of-the-day shortcut to Siri. Your app can provide this option by making a shortcut suggestion.
Suggest a Shortcut
To suggest a shortcut to an action that the user hasn’t performed but may want to add to Siri, create an INShortcutReference object with either an INIntent or NSUserActivity object that defines the action. Then add the shortcut to an array. Repeat for each suggestion your app wants to make. After creating the list of shortcut suggestions, call setShortcutSuggestions(_:), passing in the shortcuts.
import Intents
// Add a user activity to the list of suggestions.
var suggestions = [INShortcut(userActivity: orderFavoriteBeverageUserActivity)]
// Add an intent to the list of suggestions. To create
// a shortcut from an intent, the intent must be valid.
if let shortcut = INShortcut(intent: orderSoupOfTheDayIntent) {
suggestions.append(shortcut)
}
// Suggest the shortcuts.
INVoiceShortcutCenter.shared.setShortcutSuggestions(suggestions)Update Suggestions
Provide shortcut suggestions that represent actions that pertain to the user. This list may change over time for reasons such as:
The addition or removal of features from your app.
A change in the way the user interacts with your app.
To update the shortcut suggestion list, replace the existing list by calling setShortcutSuggestions(_:) and passing in a new list of suggestions. If you want to remove all suggestions made by your app, call the same method, passing in an empty array.
Changes to the list of shortcut suggestions don’t affect shortcuts the user adds to Siri. For instance, if the user adds the suggested order favorite beverage shortcut to Siri and the app removes the suggestion from the list some time later, that shortcut is still available to the user.
See Also
Articles
Adding User Interactivity with Siri Shortcuts and the Shortcuts AppDefining Relevant Shortcuts for the Siri Watch FaceDeleting Donated ShortcutsDispatching intents to handlersImproving Siri Media Interactions and App SelectionImproving interactions between Siri and your messaging appRegistering Custom Vocabulary with SiriKitConfirming the Details of an IntentHandling an IntentResolving the Parameters of an IntentGenerating a List of Ride OptionsHandling the Ride-Booking IntentsDonating ReservationsSpecifying Synonyms for Your App NameIntent Phrases