You need a physical device. Neither the iOS Simulator nor an Android emulator has an NFC
controller, so there is nothing for the library to talk to.
1. Install and build
app.json
2. Check the device before offering the feature
enabled is a real answer on both platforms here, not a hardcoded true on iOS.
On Android the user can switch NFC off while your screen is open, which is why the
React binding below subscribes rather than reading once.
3. Read a tag
The tech list is what you are willing to accept
The tech list is what you are willing to accept
The session only surfaces tags carrying one of the technologies you asked for. On iOS it also
decides which reader-session polling options are used.
Narrowing is what makes readNdef exist
Narrowing is what makes readNdef exist
Before you narrow, a
Tag has an id, a technology list and platform facets — and no technology
methods at all. tag.readNdef() on an un-narrowed tag is a compile error, not a runtime
surprise.The session is already closed by the time you read this line
The session is already closed by the time you read this line
withTag closes on every path out: returning, throwing, an AbortSignal firing, the
timeoutMs elapsing, or the platform ending the session underneath. There is no finally for
you to forget.4. Read the records you got
readNdef gives you decoded records, not bytes. Pair each decoder with its guard:
invalidArgument rather than
returning garbage, so the guard is not optional politeness — it is how you avoid
the throw. The NDEF codec covers every record type.
5. Write a tag
Check before you write. A tag that runs out of room part-way through a write is left in a state nobody can read:6. Handle the four errors that are ordinary life
Every rejection is anNfcError with a stable code. Four of them are not bugs
and not tag problems — they are what happens on an ordinary Tuesday:
7. Put it on screen
The React binding handles three things a hand-written version usually does not: unmounting mid-scan cancels the session, a secondscan() joins the first rather
than opening a second session, and NFC being switched off is reflected without a
refresh.
ScanScreen.tsx
On Android there is no system sheet, so nothing appears while
scanning is true. Show your own
“hold your tag near the phone” state — the button label above is the minimum version of that.Where to go next
Sessions
withTag is one of three ways to get a tag. The other two are for kiosks and for your own UI.Tags
Every technology, what narrowing gives you, and the platform facets.
Smartcards
DESFire and JavaCard, plus the iOS AID declaration without which the tag never arrives.
React hooks
useNfcAvailability, useNfcScan, useNfcTagStream.