简体   繁体   中英

How to add and use non native cordova plugin in ionic 5

I am trying to use this plugin in my Ionic 5 app: https://www.npmjs.com/package/cordova-plugin-k-nfc-acr122u

I installed plugin using cordova plugin add cordova-plugin-k-nfc-acr122u and ii dont now like use it. Plugin declares :

enter image description here

and i try use connect function but it don't work. enter image description here

package.json 在此处输入图片说明

Please help, thx.

You can import the plugin KNfcAcr122U from cordova-plugin-k-nfc-acr122u in your component after importing in app.module.ts.

Then in constructor you can declare a private variable private kNfcAcr122U : KNfcAcr122U

and in you function:

this.kNfcAcr122U.connect()

and

this.kNfcAcr122U.disconnect()

I solved the problem myself, maybe it will be useful to someone, Import

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

I declare:

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

and I use the connect function:

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM