返回介绍

Ionic4 Siri Shortcuts插件-Siri Shortcuts

发布于 2019-11-23 07:41:01 字数 2874 浏览 928 评论 0 收藏 0

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文