NFC

Contents

The NFC plugin allows you to read and write NFC tags. You can also beam to, and receive from, other NFC enabled devices.

https://github.com/chariotsolutions/phonegap-nfc

Ionic NFC插件的安装(Installation)

ionic cordova plugin add phonegap-nfc npm install @ionic-native/nfc

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

  • Android
  • BlackBerry 10
  • Windows
  • Windows Phone 8

Ionic NFC插件的用法(Usage)

import { NFC, Ndef } from '@ionic-native/nfc';

constructor(private nfc: NFC, private ndef: Ndef) { }

...

this.nfc.addNdefListener(() => {
  console.log('successfully attached ndef listener');
}, (err) => {
  console.log('error attaching ndef listener', err);
}).subscribe((event) => {
  console.log('received ndef message. the tag contains: ', event.tag);
  console.log('decoded tag id', this.nfc.bytesToHexString(event.tag.id));

  let message = this.ndef.textRecord('Hello world');
  this.nfc.share([message]).then(onSuccess).catch(onError);
});