Flutter教程

Siri Shortcuts

Contents

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.

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

联系我们?

If you're building a serious project, you can't afford to spend hours troubleshooting. Ionic's experts offer official maintenance, support, and integration help.

Contact Us Today!

Ionic Siri Shortcuts插件的安装(Installation)

ionic cordova plugin add cordova-plugin-siri-shortcuts npm install @ionic-native/siri-shortcuts
Ionic EE comes with fully supported and maintained plugins from the Ionic Team. Learn More or Contact Us
ionic enterprise register --key=YOURPRODUCTKEY npm install @ionic-enterprise/siri-shortcuts

Ionic Siri Shortcuts插件支持的平台(Supported Platforms)

  • iOS

Ionic Siri Shortcuts插件的用法(Usage)

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


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));