Native Capacitor plugin to read NFC tags.
To install the plugin in your project, run:
npm install --save capacitor-nfc@latest
- Android
iOS(Sorry, I do not have nor plan to acquire an iPhone. iOS contributions are welcome.)
This API requires the following permission be added to your AndroidManifest.xml:
<uses-permission android:name="android.permission.NFC" />
<uses-feature android:name="android.hardware.nfc" android:required="true" />
Specify the reason for your app to use the device’s NFC reader in Info.plist:
Name: Privacy - NFC Scan Usage Description Key: NFCReaderUsageDescription
import { Plugins } from '@capacitor/core';
const { NFC } = Plugins;
class NFCExample {
async checkNfcStatus() {
if (Capacitor.isPluginAvailable('NFC')) {
const status = NFC.getStatus();
console.log('NFC is enabled', status);
if (status !== 'enabled') {
NFC.showSettings();
}
}
}
}
getStatus
Checks whether NFC is enabled and turned on.
getTagInfo
(TODO) Returns information about the touched NFC tag.
showSettings
Opens a settings page to allow the user to enable NFC.
NFC.showSettings();