Plugin EcosystemHardware & Sensors
NFC
Read and write Near Field Communication (NFC) tags.
NFC Plugin
The NFC plugin allows your EasyCord application to read from and write to NFC tags, such as NDEF formatted cards and stickers, crucial for physical access control and asset tracking.
Installation
npm install @easycord/plugin-nfcAPI Reference
readTag()
Initiates a scan for an NFC tag and returns its NDEF messages.
Example Usage
import { useState } from 'react';
import { NFC, NFCTag } from '@easycord/plugin-nfc';
export default function NfcReader() {
const [tagData, setTagData] = useState<string | null>(null);
const scanTag = async () => {
try {
const tag: NFCTag = await NFC.readTag();
setTagData(JSON.stringify(tag.ndefMessage, null, 2));
} catch (err) {
console.error('NFC Read Error:', err);
}
};
return (
<div className="p-4">
<button onClick={scanTag} className="bg-indigo-600 text-white px-4 py-2 rounded">
Scan NFC Tag
</button>
{tagData && (
<pre className="mt-4 bg-gray-100 p-2 rounded text-sm">
{tagData}
</pre>
)}
</div>
);
}