Skip to main content
@capgo/capacitor-nfc Device APIs Open source

NFC Capacitor plugin

Native NFC tag discovery, reading and writing for Capacitor apps on iOS and Android

Install

bun add @capgo/capacitor-nfc bunx cap sync
npm, pnpm or yarn
  • npm install @capgo/capacitor-nfc
  • pnpm add @capgo/capacitor-nfc
  • yarn add @capgo/capacitor-nfc

Guide

How to use NFC in Capacitor

Test on device

Download the Capgo app, then scan the QR code.

NFC plugin preview QR code

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.

FAQ

NFC plugin FAQ

How do I install the NFC plugin in a Capacitor app?

Run "bun add @capgo/capacitor-nfc" (or "npm install @capgo/capacitor-nfc"), then run "bunx cap sync" so the iOS and Android projects pick up the native code. Import it from "@capgo/capacitor-nfc" in your app code.

Does @capgo/capacitor-nfc work with React, Vue and Angular?

Yes. NFC is a Capacitor package, so it works with any web framework that runs inside Capacitor, including Ionic, React, Vue, Angular, Svelte and plain JavaScript.

Which Capacitor version does @capgo/capacitor-nfc support?

Capgo plugins follow Capacitor's major version: use the plugin major version that matches your Capacitor major version (for example plugin v8 with Capacitor 8). The compatibility table in the GitHub README lists the maintained versions.

Is @capgo/capacitor-nfc free and open source?

Yes. The source code is public on GitHub at https://github.com/Cap-go/capacitor-nfc/ and the package is free to install from npm. Bug reports and pull requests are welcome.

Can I update code that uses NFC without an App Store review?

Installing or upgrading the plugin changes native code, so it needs a new store build. After that, JavaScript, HTML and CSS changes that call the plugin can ship instantly with Capgo live updates.

Ship NFC changes without waiting for app review

Once the plugin is in your store build, Capgo live updates push your JavaScript, HTML and CSS changes to users in minutes.

Start with Capgo