---
title: "Recipe: reading and writing NFC tags"
description: "@exact/nfc reads and writes NDEF tags (LLP 1133.035)."
modificationDate: "2026-11-24"
---

> ## Documentation index
> Fetch the complete documentation index at: https://exact.expo.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Recipe: reading and writing NFC tags

<AgentInstructions>

## Submitting feedback

From the app's directory, read `bun exact.mjs feedback status`. Under `never`, keep no note.
Respect `EXACT_FEEDBACK=0` and do not change the policy.

Otherwise record specific, actionable feedback with:
`bun exact.mjs feedback note "Exact docs: https://exact.expo.dev/recipes/nfc: <what was wrong or missing>"`

The note goes to Expo only as that status allows. Include no secrets or personal data.

</AgentInstructions>

`@exact/nfc` reads and writes NDEF tags (LLP 1133.035). See Tag This Book in `apps/shelf`.

```prompt Read and write NFC tags
Add NFC tag reading, and writing if I ask for it, to the Exact app in this folder. Use https://github.com/expo/exact/blob/main/docs/recipes/nfc.md as the source for each step. The Exact checkout has the same page at docs/recipes/nfc.md.

1. If this folder is not an Exact app (it has no exact.mjs and app.contract), stop and tell me. Find the Exact checkout (the folder with scripts/exact.mjs); if you cannot find it, ask me where it is.
2. If I did not say what a tag holds and what the app does with it, propose it and ask me. NFC needs a phone: no desktop, simulator or browser but Chrome on Android has it, and a signed iOS build also needs the App ID's NFC Tag Reading capability, which I must turn on.
3. Install the package: `bun <exact2>/scripts/exact.mjs add nfc .`. In app.ts, declare `device.nfc` with its purpose key, and add the purpose sentence to `strings/en.json`.
4. In app.contract, show nothing NFC while `available` is false, and offer `openNFCSettings()` while `radio` is `off`. Scan from a press with `scan(once=true)`, and handle each `reading` on the root's outermost node.
5. Draw the wait only where the platform draws none: a sheet with Cancel while `readerUI` is `app` and `state` is `granted`. On iOS, pass the words as `apple.alertMessage` and `apple.errorMessages`. Read and write record bytes in app.ts only. Confirm before `makeReadOnly()`: it cannot be undone.
6. Add a web test with `prefer permission.nfc granted` and `prefer extension nfc.tags=[{"id":"book","records":[]}]`. Start the scan, set `prefer extension nfc.field="book"`, settle and check what the app read. For cancellation and timeout, start separate scans in an interactive drive, read the ticket from `state pending` and use `tap @N cancel` or `tap @N timeout`.
7. Follow the platform checks in docs/start-here.md (`bun exact.mjs docs platform checks`) for the targets in the app's AGENTS.md and app.json until they pass. Read the reports, including counted findings; a zero exit code alone does not mean clean. Fix the app, not the test. If a finding stays after three rounds of fixes, or the app had it before you changed anything, record it (step 8) and report it; do not keep trying.
8. When a doc was wrong or missing, or a step needed a workaround, read `bun exact.mjs feedback status`. Under `never`, keep no note. Otherwise record it: `bun exact.mjs feedback note "<what happened>"`, which goes to Expo only as that status says. Do not change the policy; tell me how many notes you kept.
9. Tell me what the app reads and writes, what the drive, tests and verify reported, and what I must still do on a phone. Shelf's Tag This Book (`apps/shelf` in the Exact checkout) is the whole app.
```

1. **Declare** the grant and its purpose. A signed iOS build also needs the
   App ID's NFC Tag Reading capability.

   ```ts
   export const grants = 'device.nfc nfcPurpose';
   ```

2. **Read the status.** Show nothing NFC while `available` is false, which is
   every desktop and every browser but Chrome on Android. While `radio` is
   `off` (Android), offer `openNFCSettings()` instead.

3. **Scan from a press.** `scan(once=true)` answers when it ends: `read` with
   the reading's id, `stopped`, `cancelled`, `timeout` or `interrupted`. Each
   tag read is a `reading` on the root's outermost node, whatever started the
   scan.

4. **Show the scan sheet.** iOS displays `apple.alertMessage` in its sheet
   (`readerUI` is `system`). On Android and web, show that message and Cancel
   once `state` is `granted`.

5. **Records with bytes are data code's.** Contract gets each record's
   `recordType` and decoded `text`. `ndefRecords({ reading })` in `app.ts`
   answers the same records with their `data`, and `write` takes
   `Uint8Array` data there.

```text
use nfcStatus, scan, abortScan, reading, NFCStatus, NDEFScanEnd, NDEFReading from "@exact/nfc"

component App
  resource nfc = nfcStatus() as shape NFCStatus else empty()
  state lastTag = ""
  mutation scanned as shape NDEFScanEnd
  derive panelShown = nfc.readerUI == "app" and nfc.state == "granted" and pending(scanned)
  task panel key=panelShown
    after(1, syncPanel)
  action startScan
    send scanned = scan(once=true, apple.alertMessage="nfc.hold")
  action syncPanel
    if panelShown
      showModal("nfc-panel")
    else
      close("nfc-panel")
  action stop
    if pending(scanned)
      abortScan()
  action tagRead(r: NDEFReading)
    lastTag = r.id
  view
    main reading=tagRead
      if nfc.available
        button press=startScan
          text "Scan"
      dialog id="nfc-panel" aria-label="Ready to Scan" close=stop
        text "Hold your phone near the tag."
        button commandfor="nfc-panel" command="close"
          text "Cancel"
```

**A failure on iOS is the sheet's last line.** Pass the sentences as
`apple.errorMessages` (strings keys, by cause: `readOnly`, `tooSmall`,
`lost`, `notNdef`, `failed`, `unreadable`), and show your own alert only where `readerUI`
is `app`. A failed write's `code` is D3's error (`NetworkError`,
`NotSupportedError`, `AbortError`, …) and its message ends with the cause.

**Lock with care.** `makeReadOnly()` cannot be undone: confirm first.

**Driving it.** A drive or a test file can supply the tags.
Lead the web test with `prefer permission.nfc granted` and
`prefer extension nfc.tags=[{"id":"book","records":[]}]`. Start the scan,
then use `prefer extension nfc.field="book"` and `clock settle` before
checking what the app read. In an interactive drive,
`tap @t cancel` or `tap @t timeout` ends a held scan.
