Ionic Framework 4 is almost here. Preview the beta docs and try it out now! Try Ionic 4 Beta

Siri Shortcutsβ

Improve this doc

This plugin is still in beta stage and may not work as expected. Please submit any issues to the plugin repo.

This plugin only works when your app is built with XCode 10. Shortcuts will only appear on iOS-versions >= 12.0

This plugin enables the use of Siri shortcuts in Cordova. Siri Shortcuts enable the user to perform certain actions by adding them to Siri. After you have donated a shortcut to Siri, it will appear in the settings menu, after which the user is able to add the action. You can check whether the user launched your app through a shortcut by calling getActivatedShortcut() when the app is resumed. It will return null if it has not been launched by Siri, and if it did, it will return an object with SiriShortcut properties.

Repo: https://github.com/bartwesselink/cordova-plugin-siri-shortcuts

Installation

  1. Install the Cordova and Ionic Native plugins:
    $ ionic cordova plugin add cordova-plugin-siri-shortcuts
    $ npm install --save @ionic-native/siri-shortcuts
    
  2. Add this plugin to your app's module

Supported platforms

Usage

import { SiriShortcuts } from '@ionic-native/siri-shortcuts';


constructor(private siriShortcuts: SiriShortcuts) { }

...


this.siriShortcuts.donate({
      persistentIdentifier: 'open-my-app',
      title: 'Open my app',
      suggestedInvocationPhrase: 'Open my app',
      userInfo: { username: 'username' },
      isEligibleForSearch: true,
      isEligibleForPrediction: true,
  })
  .then(() => console.log('Shortcut donated.'))
  .catch((error: any) => console.error(error));

this.siriShortcuts.present({
      persistentIdentifier: 'open-my-app',
      title: 'Open my app',
      suggestedInvocationPhrase: 'Open my app',
      userInfo: { username: 'username' },
  })
  .then(() => console.log('Shortcut added.'))
  .catch((error: any) => console.error(error));

this.siriShortcuts.remove('open-my-app')
  .then(() => console.log('Shortcut removed.'))
  .catch((error: any) => console.error(error));

this.siriShortcuts.removeAll()
  .then(() => console.log('All shortcuts removed removed.'))
  .catch((error: any) => console.error(error));

this.siriShortcuts.getActivatedShortcut()
  .then((data: SiriShortcut|null) => console.log(data))
  .catch((error: any) => console.error(error));

Instance Members

donate(options, options.persistentIdentifier, options.title, options.suggestedInvocationPhrase, options.userInfo, options.isEligibleForSearch, options.isEligibleForPrediction)

Donate shortcut to Siri

Param Type Details
options SiriShortcutOptions

Options to specify for the donation

options.persistentIdentifier string

Specify an identifier to uniquely identify the shortcut, in order to be able to remove it

options.title string

Specify a title for the shortcut, which is visible to the user as the name of the shortcut

options.suggestedInvocationPhrase string

Specify the phrase to give the user some inspiration on what the shortcut to call

options.userInfo object

Provide a key-value object that contains information about the shortcut, this will be returned in the getActivatedShortcut method. It is not possible to use the persistentIdentifier key, it is used internally

options.isEligibleForSearch boolean

This value defaults to true, set this value to make it searchable in Siri

options.isEligibleForPrediction boolean

This value defaults to true, set this value to set whether the shortcut eligible for prediction

Returns: Promise

present(options, options.persistentIdentifier, options.title, options.suggestedInvocationPhrase, options.userInfo, options.isEligibleForSearch, options.isEligibleForPrediction)

Present shortcut to the user, will popup a view controller asking the user to add it to Siri

Param Type Details
options SiriShortcutOptions

Options to specify for the donation

options.persistentIdentifier string

Specify an identifier to uniquely identify the shortcut, in order to be able to remove it

options.title string

Specify a title for the shortcut, which is visible to the user as the name of the shortcut

options.suggestedInvocationPhrase string

Specify the phrase to give the user some inspiration on what the shortcut to call

options.userInfo object

Provide a key-value object that contains information about the shortcut, this will be returned in the getActivatedShortcut method. It is not possible to use the persistentIdentifier key, it is used internally

options.isEligibleForSearch boolean

This value defaults to true, set this value to make it searchable in Siri

options.isEligibleForPrediction boolean

This value defaults to true, set this value to set whether the shortcut eligible for prediction

Returns: Promise

remove(persistentIdentifiers)

Remove shortcuts based on identifiers

Param Type Details
persistentIdentifiers string|Array.<string>

Specify which shortcut(s) to delete by their persistent identifiers

Returns: Promise

removeAll()

Remove all shortcuts from the application

Returns: Promise

getActivatedShortcut(options, options.clear)

Get the current clicked user activity, and return null if none

Param Type Details
options ActivatedShortcutOptions|null

Options to specify for getting the shortcut

options.clear boolean

Clear the currently activated shortcut, defaults to true

Returns: Promise<SiriShortcut|null>

SiriShortcut

Param Type Details
persistentIdentifier string
title string
userInfo { [key: string]: string; }
suggestedInvocationPhrase string

SiriShortcutOptions

Param Type Details
isEligibleForSearch boolean (optional)
isEligibleForPrediction boolean (optional)

ActivatedShortcutOptions

Param Type Details
clear boolean (optional)

API

Native

General