Communicate with physical NFC tags from your web app. The runtime activates the device’s NFC chip in either read or write mode, and the next tag the user taps against the phone is processed.Documentation Index
Fetch the complete documentation index at: https://setup.despia.com/llms.txt
Use this file to discover all available pages before exploring further.
The device must have NFC hardware. All modern iPhones from XS onwards and most Android phones support NFC, but some budget Android models do not. On devices without NFC, the call resolves silently.
Installation
- Bundle
- CDN
Setup
NFC on iOS is a capability that has to be enabled on the App ID itself before the runtime can access the NFC chip. Enable it in Apple Developer, toggle the addon in the Despia Editor, then rebuild.Open Apple Developer
Sign in at developer.apple.com and go to Certificates, Identifiers & Profiles > Identifiers.
Open your core bundle ID
Select the App ID that matches your app’s core bundle ID (the one Despia builds against).
Enable NFC Tag Reading
Under Capabilities, tick NFC Tag Reading and save. Apple regenerates the provisioning profile with the new entitlement.
How it works
NFC has two modes, read and write. Each mode is triggered by its own scheme call, and results flow back through a global event callback onwindow.
Handling NFC events
Definewindow.onNFCEvent once at app startup. The runtime invokes it with a single object whenever something happens during an active NFC session, whether a tag is read, a write completes, the user cancels, or anything goes wrong.
Fires when a tag is successfully scanned in read mode. Carries
id, the tag’s unique identifier as a lowercase hex string (empty string if the device cannot read it), and data, the NDEF payload content as a string.Fires when a write completes successfully. No additional fields.
Fires when the user closes the system NFC sheet before a tag is scanned. No additional fields.
Fires on any other failure, read or write. Carries
error, a human-readable message describing what went wrong.dismissed or error, the in-flight action is cleared as soon as the success event fires. You can treat the four event types as mutually exclusive per session.
Reading NFC tags
Callnfc://read to enter read mode. When the user taps a tag, the runtime fires window.onNFCEvent({ type: 'read', id, data }) with the tag identifier and the NDEF payload.
Writing to NFC tags
Pass the value to write as thevalue query parameter. The runtime enters write mode, the next tag the user taps receives the payload, and window.onNFCEvent({ type: 'write' }) fires when the write completes.
encodeURIComponent. Without it, URLs with ?, &, or = inside the payload will break the scheme parse on the native side.
Trigger the write from any UI element:
Handling cancellation and failure
The runtime distinguishes between the user closing the NFC sheet and an actual failure. Adismissed event fires when the user backs out before a tag is scanned, and is not an error condition. An error event fires for everything else, including malformed tags, tags that are not NDEF formatted, write failures, and session timeouts.
error message is a passthrough of the underlying platform error string, suitable for logging or developer-facing diagnostics. For end-user messaging, map the type to your own copy rather than displaying the raw string.
Writing a vCard
To write a contact card that a phone can save directly from a tap, format the payload as a vCard string prefixed withVCARD_ and join the properties with underscores.
FN, ORG, EMAIL, URL, ADR, TEL, and the rest). When another phone reads the tag, the OS recognises the vCard and offers to save the contact natively.
Resources
NPM Package
despia-native