Using @capgo/capacitor-nfc
Public API surface for the Capacitor NFC plugin.
Install
bun add @capgo/capacitor-nfc
bunx cap sync
bunx cap sync copies the plugin's native code into your native projects. Run it again after every plugin upgrade.
Import
import { CapacitorNfc } from '@capgo/capacitor-nfc';
API at a glance
| Method | Description |
|---|---|
startScanning |
Starts listening for NFC tags. |
stopScanning |
Stops the ongoing NFC scanning session. |
write |
Writes the provided NDEF records to the last discovered tag. |
erase |
Attempts to erase the last discovered tag by writing an empty NDEF message. |
makeReadOnly |
Attempts to make the last discovered tag read-only. |
share |
Shares an NDEF message with another device via peer-to-peer (Android only). |
unshare |
Stops sharing previously provided NDEF message (Android only). |
getStatus |
Returns the current NFC adapter status. |
showSettings |
Opens the system settings page where the user can enable NFC. |
isSupported |
Checks whether the device has NFC hardware support. |
Examples
startScanning()
Starts listening for NFC tags.
import { CapacitorNfc } from '@capgo/capacitor-nfc';
await CapacitorNfc.startScanning();
stopScanning()
Stops the ongoing NFC scanning session.
import { CapacitorNfc } from '@capgo/capacitor-nfc';
await CapacitorNfc.stopScanning();
write()
Writes the provided NDEF records to the last discovered tag.
import { CapacitorNfc } from '@capgo/capacitor-nfc';
await CapacitorNfc.write({
records: [
{
tnf: 1,
type: [1],
id: [1],
payload: [1],
},
],
});
erase()
Attempts to erase the last discovered tag by writing an empty NDEF message.
import { CapacitorNfc } from '@capgo/capacitor-nfc';
await CapacitorNfc.erase();
makeReadOnly()
Attempts to make the last discovered tag read-only.
import { CapacitorNfc } from '@capgo/capacitor-nfc';
await CapacitorNfc.makeReadOnly();
share()
Shares an NDEF message with another device via peer-to-peer (Android only).
import { CapacitorNfc } from '@capgo/capacitor-nfc';
await CapacitorNfc.share({
records: [
{
tnf: 1,
type: [1],
id: [1],
payload: [1],
},
],
});
The table above lists the 10 core methods. Listener and version helpers, and the full contract of each method, are documented in the GitHub repository.
Listen to events
addListener returns a handle. Call handle.remove() when the screen unmounts.
Full reference
Keep going from Using @capgo/capacitor-nfc
If you are using Using @capgo/capacitor-nfc to plan dashboard and API operations, connect it with @capgo/capacitor-nfc for the implementation detail in @capgo/capacitor-nfc, Getting Started for the implementation detail in Getting Started, API Overview for the implementation detail in API Overview, Introduction for the implementation detail in Introduction, and API Keys for the implementation detail in API Keys.