【问题标题】:How to add and use non native cordova plugin in ionic 5如何在 ionic 5 中添加和使用非原生 cordova 插件
【发布时间】:2021-11-30 17:58:51
【问题描述】:

我正在尝试在我的 Ionic 5 应用中使用这个插件:https://www.npmjs.com/package/cordova-plugin-k-nfc-acr122u

我使用cordova插件安装了插件,添加了cordova-plugin-k-nfc-acr122u,我现在不喜欢使用它。插件声明:

enter image description here

我尝试使用连接功能,但它不起作用。 enter image description here

package.json

请帮忙,谢谢。

【问题讨论】:

  • 检查这个插件“ionicframework.com/docs/native/nfc”
  • 感谢您的建议。我只需要 k-nfc-acr122u 插件,因为我有 USB nfc 适配器,我尝试连接到这个。

标签: javascript typescript ionic-framework ionic-plugins


【解决方案1】:

我自己解决了这个问题,也许对某人有用, 导入

 import { KNfcAcr122U } from 'plugins/cordova-plugin-k-nfc-acr122u/types';

我声明:

 const kNfcAcr122U: KNfcAcr122U = window['KNfcAcr122U'];

我使用连接功能:

kNfcAcr122U.connect(this.callbackSuccess, this.callbackError);

callbackSuccess(event): void {
  console.log(event,'success');  
}

callbackError(): void {
  console.log('error');
}

【讨论】:

    【解决方案2】:

    在 app.module.ts 中导入后,您可以在组件中从 cordova-plugin-k-nfc-acr122u 导入插件 KNfcAcr122U。

    然后在构造函数中你可以声明一个私有变量 private kNfcAcr122U : KNfcAcr122U

    在你的功能中:

    this.kNfcAcr122U.connect()

    和

    this.kNfcAcr122U.disconnect()

    【讨论】:

    • 谢谢,但我没有在 app.module.ts 中导入。我有这样一个错误:'KNfcAcr122U' 仅指一种类型,但在此处用作值。ts
    猜你喜欢
    • 2019-02-05
    • 1970-01-01
    • 2017-11-22
    • 1970-01-01
    • 2018-01-01
    • 2018-02-23
    • 2018-08-05
    • 2017-07-04
    相关资源
    最近更新 更多