public class SiriIntegration
extends Object
Siri is available only on iOS devices running iOS 12.0 or later.
This class provides APIs that enable integration of Siri with a MAF application.
There are several ways that Siri shortcuts can utilized:
Siri Shortcut Suggestions
An application may provide Siri shortcut suggestions programatically. These shortcuts are exposed in the Siri section of the application's entry in the iOS Settings application. Users can opt to enable these shortcuts and record a voice phrase used to invoke them.
Add to Siri
A shortcut can be created and directly added within the application using the native Siri user interface. These are typically exposed with an "Add to Siri" button or similar action to allow the triggering of an action through a phrase spoken to Siri.
Donating Shortcuts
Shortcuts can be donated to the operating system when a user performs a particular activity. Donating shortcuts allows the OS to predict display the shortcut in Siri search results, the lock screen, and on the Siri watch face. Users may also record voice phrases to invoke donated shortcuts directly.
Donated shortcuts should be configured with a persistent identifier. They can be deleted using that persistent identifier should they no longer be relevant, for example if they are a shortcut to something that is no longer available.
In all cases, when a user invokes a shortcut the app is launched or foregrounded if already running and the shortcut is delivered through the MAF event system. Applications can listen for these shortcuts and perform appropriate action when they are invoked by the user.
Integration with Siri requires the explicit authorization by the user. Always use the requestSiriPermission API and validate the authorization prior to using any other Siri related API.
Refer to the SiriDemo public sample for examples on how to configure and use Siri within a MAF application.
Modifier and Type | Class and Description |
---|---|
static class |
SiriIntegration.SiriAuthorizationStatus
Constants indicating the authorization status of Siri
|
static class |
SiriIntegration.SiriEditShortcutStatus
Constants indicating the result of editing a siri shortcut
|
Constructor and Description |
---|
SiriIntegration() |
Modifier and Type | Method and Description |
---|---|
static void |
addToSiri(SiriShortcut shortcut)
Add a siri shortcut
Use this API to respond to a user invoked action, such as a "Add to Siri" button within the application.
|
static void |
deleteAllShortcuts()
Remove all donated shortcuts
|
static void |
deleteShortcut(String persistentIdentifier)
Remove a Siri shortcut with the specified persistent identifier
|
static void |
donateShortcut(SiriShortcut shortcut) |
static void |
editWithSiri(String systemIdentifier,
java.util.function.Consumer<SiriIntegration.SiriEditShortcutStatus> callback)
Edit an existing shortcut
Editing involves displaying a native dialog that allows the user to re-record the phrase used to invoke
the shortcut.
|
static java.util.List<SiriShortcut> |
getSiriShortcuts() |
static void |
requestAuthorization(java.util.function.Consumer<SiriIntegration.SiriAuthorizationStatus> callback)
Request authorization to utilize Siri
This method should be invoked and result handled appropriately prior to any use of Siri related methods.
|
static void |
setSiriShortcutSuggestions(java.util.List<SiriShortcut> siriShortcuts)
Set Siri shortcut suggestions
To suggest shortcuts for actions that the user hasn’t performed in your app but may want to add to Siri,
call setSiriShortcuts passing in a list of suggested shortcuts.
|
public static void requestAuthorization(java.util.function.Consumer<SiriIntegration.SiriAuthorizationStatus> callback)
callback
- the callback invoked with the authorization status once determinedpublic static java.util.List<SiriShortcut> getSiriShortcuts()
public static void setSiriShortcutSuggestions(java.util.List<SiriShortcut> siriShortcuts)
siriShortcuts
- the suggested siri shortcutspublic static void addToSiri(SiriShortcut shortcut)
public static void editWithSiri(String systemIdentifier, java.util.function.Consumer<SiriIntegration.SiriEditShortcutStatus> callback)
systemIdentifier
- The system identifier associated with the shortcut to editcallback
- An optional callback invoked asynchronously on the calling feature with the result of the editpublic static void donateShortcut(SiriShortcut shortcut)
public static void deleteShortcut(String persistentIdentifier)
systemIdentifer
- The persistent identifier of the shortcutpublic static void deleteAllShortcuts()