Ir al contenido

@tauri-apps/plugin-nfc

Esta página aún no está disponible en tu idioma.

Read and write NFC tags on Android and iOS.

This plugin is mobile only, the APIs reject on desktop platforms.

Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/nfc/guest-js/index.ts#L151

The Type Name Format (TNF) of an NDEF record, which defines how the record type is interpreted.

AbsoluteURI: 3;

Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/nfc/guest-js/index.ts#L162

The record type is an absolute URI as defined in RFC 3986.

Empty: 0;

Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/nfc/guest-js/index.ts#L153

The record is empty: type, identifier and payload must be empty.

Media: 2;

Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/nfc/guest-js/index.ts#L160

The record type is a MIME media type as defined in RFC 2046, e.g. text/plain.

NfcExternal: 4;

Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/nfc/guest-js/index.ts#L164

The record type is an NFC Forum external type, i.e. a type namespaced by its issuer.

NfcWellKnown: 1;

Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/nfc/guest-js/index.ts#L158

The record type is an NFC Forum well known type, defined by a Record Type Definition (RTD) such as RTD_TEXT or RTD_URI.

Unchanged: 6;

Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/nfc/guest-js/index.ts#L174

The record is a middle or last chunk of a chunked record and inherits the type of the first chunk, so its own type must be empty.

Unknown: 5;

Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/nfc/guest-js/index.ts#L169

The record type is unknown: the type must be empty and the payload interpretation is left to the application.


Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/nfc/guest-js/index.ts#L48

The NFC technologies a tag can support, mirroring the android.nfc.tech classes.

Android only, used by the techLists filter of an ndef ScanKind.

IsoDep: 0;

Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/nfc/guest-js/index.ts#L50

ISO-DEP (ISO 14443-4) properties and I/O operations.

MifareClassic: 1;

Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/nfc/guest-js/index.ts#L52

MIFARE Classic properties and I/O operations.

MifareUltralight: 2;

Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/nfc/guest-js/index.ts#L54

MIFARE Ultralight and MIFARE Ultralight C properties and I/O operations.

Ndef: 3;

Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/nfc/guest-js/index.ts#L56

NDEF data and operations on tags that are already formatted as NDEF.

NdefFormatable: 4;

Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/nfc/guest-js/index.ts#L58

Formatting operations on tags that can be formatted as NDEF but are not yet.

NfcA: 5;

Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/nfc/guest-js/index.ts#L60

NFC-A (ISO 14443-3A) properties and I/O operations.

NfcB: 6;

Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/nfc/guest-js/index.ts#L62

NFC-B (ISO 14443-3B) properties and I/O operations.

NfcBarcode: 7;

Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/nfc/guest-js/index.ts#L64

NFC Barcode (Kovio NFC Barcode) properties and I/O operations.

NfcF: 8;

Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/nfc/guest-js/index.ts#L66

NFC-F (JIS 6319-4) properties and I/O operations.

NfcV: 9;

Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/nfc/guest-js/index.ts#L68

NFC-V (ISO 15693) properties and I/O operations.

Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/nfc/guest-js/index.ts#L207

An NDEF record to be written to a tag.

Use record, textRecord or uriRecord to create one.

Property Type Description Defined in
format NFCTypeNameFormat The Type Name Format (TNF) of the record. Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/nfc/guest-js/index.ts#L209
id number[] The record identifier. Can be empty. Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/nfc/guest-js/index.ts#L217
kind number[] The record type, interpreted according to NFCRecord.format. For well known records this is a Record Type Definition (RTD) value such as RTD_TEXT or RTD_URI. Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/nfc/guest-js/index.ts#L215
payload number[] The record payload bytes. Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/nfc/guest-js/index.ts#L219

Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/nfc/guest-js/index.ts#L119

Options for the scan function.

Property Type Description Defined in
keepSessionAlive? boolean Whether the connection to the scanned tag must be kept open after the scan resolves, so that a following write call writes to that tag instead of scanning a new one. Defaults to false. Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/nfc/guest-js/index.ts#L125
message? string Message displayed in the UI. iOS only. Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/nfc/guest-js/index.ts#L127
successMessage? string Message displayed in the UI when the message has been read. iOS only. Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/nfc/guest-js/index.ts#L129

Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/nfc/guest-js/index.ts#L193

An NFC tag that has been scanned.

Property Type Description Defined in
id number[] The tag identifier bytes, as reported by the operating system. Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/nfc/guest-js/index.ts#L195
kind string[] The technologies the tag supports, e.g. ["android.nfc.tech.Ndef"] on Android. Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/nfc/guest-js/index.ts#L197
records TagRecord[] The NDEF records stored on the tag. Empty when the tag holds no NDEF message. Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/nfc/guest-js/index.ts#L199

Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/nfc/guest-js/index.ts#L178

An NDEF record read from a scanned tag.

Property Type Description Defined in
id number[] The record identifier bytes. Can be empty. Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/nfc/guest-js/index.ts#L187
kind number[] The record type bytes. Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/nfc/guest-js/index.ts#L185
payload number[] The record payload bytes. Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/nfc/guest-js/index.ts#L189
tnf NFCTypeNameFormat The Type Name Format (TNF) of the record, which defines how TagRecord.kind is interpreted. Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/nfc/guest-js/index.ts#L183

Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/nfc/guest-js/index.ts#L34

Filters the tags to scan by the URI of their payload.

Every property is optional and only the ones that are set take part in the filter. Android only, the iOS implementation ignores this filter.

Property Type Description Defined in
host? string Only match URIs with this authority (host), e.g. tauri.app. Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/nfc/guest-js/index.ts#L38
pathPrefix? string Only match URIs whose path starts with this prefix, e.g. /docs. Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/nfc/guest-js/index.ts#L40
scheme? string Only match URIs with this scheme, e.g. https. Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/nfc/guest-js/index.ts#L36

Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/nfc/guest-js/index.ts#L133

Options for the write function.

Property Type Description Defined in
kind? ScanKind The kind of scan to perform to find the tag to write to. Required on Android unless a scan session is kept alive. Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/nfc/guest-js/index.ts#L138
message? string Message displayed in the UI when reading the tag. iOS only. Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/nfc/guest-js/index.ts#L140
successfulReadMessage? string Message displayed in the UI when the tag has been read. iOS only. Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/nfc/guest-js/index.ts#L142
successMessage? string Message displayed in the UI when the message has been written. iOS only. Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/nfc/guest-js/index.ts#L144

type ScanKind =
| {
mimeType?: string;
type: "tag";
uri?: UriFilter;
}
| {
mimeType?: string;
techLists?: TechKind[][];
type: "ndef";
uri?: UriFilter;
};

Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/nfc/guest-js/index.ts#L76

The kind of scan to perform, which defines which tags are matched.

Use tag to match any discovered tag and ndef to only match tags carrying an NDEF message.

{
mimeType?: string;
type: "tag";
uri?: UriFilter;
}
Name Type Description Defined in
mimeType? string Only match tags whose payload has this MIME type, e.g. text/plain. Android only. Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/nfc/guest-js/index.ts#L83
type "tag" Matches any tag that is discovered, whether it carries an NDEF message or not. Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/nfc/guest-js/index.ts#L79
uri? UriFilter Only match tags whose payload URI matches this filter. Android only. Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/nfc/guest-js/index.ts#L81

{
mimeType?: string;
techLists?: TechKind[][];
type: "ndef";
uri?: UriFilter;
}
Name Type Description Defined in
mimeType? string Only match tags whose NDEF payload has this MIME type, e.g. text/plain. Android only. Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/nfc/guest-js/index.ts#L94
techLists? TechKind[][] Each of the tech-lists is considered independently and the activity is considered a match if any single tech-list matches the tag that was discovered. This provides AND and OR semantics for filtering desired techs. See https://developer.android.com/reference/android/nfc/NfcAdapter#ACTION_TECH_DISCOVERED for more information. Examples import type { TechKind } from "@tauri-apps/plugin-nfc" const techLists = [ // capture anything using NfcF [TechKind.NfcF], // capture all MIFARE Classics with NDEF payloads [TechKind.NfcA, TechKind.MifareClassic, TechKind.Ndef] ] Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/nfc/guest-js/index.ts#L115
type "ndef" Only matches tags that carry an NDEF message. Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/nfc/guest-js/index.ts#L87
uri? UriFilter Only match tags whose NDEF payload URI matches this filter. Android only. Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/nfc/guest-js/index.ts#L89

const RTD_TEXT: number[];

Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/nfc/guest-js/index.ts#L20

Record Type Definition (RTD) of an NDEF well known text record, the "T" (0x54) byte.

2.0.0


const RTD_URI: number[];

Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/nfc/guest-js/index.ts#L26

Record Type Definition (RTD) of an NDEF well known URI record, the "U" (0x55) byte.

2.0.0

function isAvailable(): Promise<boolean>;

Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/nfc/guest-js/index.ts#L464

Checks whether NFC is supported by the device and currently usable by the app.

Resolves to false on Android when the device has no NFC adapter or NFC is disabled in the device settings, and on iOS when the NFCReaderUsageDescription entry is missing from the Info.plist file or NFC tag reading is unavailable.

Promise<boolean>

A promise resolving to whether NFC is available on the device.

import { isAvailable } from '@tauri-apps/plugin-nfc';
const canScan = await isAvailable();

2.0.0


function record(
format,
kind,
id,
payload
): NFCRecord;

Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/nfc/guest-js/index.ts#L242

Creates an NDEF record with the given type name format, type, identifier and payload.

Strings are encoded as UTF-8 byte arrays.

Parameter Type Description
format NFCTypeNameFormat The Type Name Format (TNF) of the record.
kind string | number[] The record type, interpreted according to format.
id string | number[] The record identifier. Use an empty string or array when the record has none.
payload string | number[] The record payload.

NFCRecord

The NDEF record, ready to be written with write.

import { record, NFCTypeNameFormat, write } from '@tauri-apps/plugin-nfc';
const mimeRecord = record(NFCTypeNameFormat.Media, 'text/plain', '', 'hello world');
await write([mimeRecord], { kind: { type: 'ndef' } });

2.0.0


function scan(kind, options?): Promise<Tag>;

Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/nfc/guest-js/index.ts#L404

Scans an NFC tag, resolving when a tag matching the given filters is read.

See https://developer.android.com/develop/connectivity/nfc/nfc#ndef for more information.

Parameter Type Description
kind ScanKind The kind of scan to perform, which defines how tags are matched.
options? ScanOptions Additional scan options such as the iOS UI messages and whether the session must be kept alive for a following write call.

Promise<Tag>

A promise resolving to the tag that has been scanned.

import { scan } from '@tauri-apps/plugin-nfc';
const tag = await scan({ type: 'tag' });

2.0.0


function textRecord(
text,
id?,
language?
): NFCRecord;

Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/nfc/guest-js/index.ts#L281

Creates an NDEF well known text record (RTD_TEXT).

The payload is the UTF-8 encoded text prefixed by the language code and by a status byte holding the length of that language code.

Parameter Type Default value Description
text string undefined The text to store in the record.
id? string | number[] undefined The record identifier. Defaults to an empty identifier.
language? string 'en' The IANA language code of the text. Defaults to en.

NFCRecord

The NDEF record, ready to be written with write.

import { textRecord, write } from '@tauri-apps/plugin-nfc';
await write([textRecord('hello world')], { kind: { type: 'ndef' } });

2.0.0


function uriRecord(uri, id?): NFCRecord;

Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/nfc/guest-js/index.ts#L372

Creates an NDEF well known URI record (RTD_URI).

The URI is encoded with the NDEF URI abbreviation scheme: a known prefix such as https:// is replaced by the identifier code byte that starts the payload.

Parameter Type Description
uri string The URI to store in the record.
id? string | number[] The record identifier. Defaults to an empty identifier.

NFCRecord

The NDEF record, ready to be written with write.

import { uriRecord, write } from '@tauri-apps/plugin-nfc';
await write([uriRecord('https://tauri.app')], { kind: { type: 'ndef' } });

2.0.0


function write(records, options?): Promise<void>;

Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/nfc/guest-js/index.ts#L432

Write to an NFC tag.

If you did not previously call scan with ScanOptions.keepSessionAlive set to true, it will first scan the tag then write to it.

Parameter Type Description
records NFCRecord[] The NDEF records to write to the tag.
options? WriteOptions Additional write options such as the kind of scan used to find the tag and the iOS UI messages.

Promise<void>

import { uriRecord, write } from '@tauri-apps/plugin-nfc';
await write([uriRecord('https://tauri.app')], { kind: { type: 'ndef' } });

2.0.0


© 2026 Tauri Contributors. CC-BY / MIT