Saltare al contenuto

Inizia

Finestra del terminale
bun add @capgo/capacitor-nfc
bunx cap sync
import { CapacitorNfc } from '@capgo/capacitor-nfc';

Ascolta i tag NFC.

import { CapacitorNfc } from '@capgo/capacitor-nfc';
await CapacitorNfc.startScanning();

Interrompe la sessione di scansione NFC in corso.

import { CapacitorNfc } from '@capgo/capacitor-nfc';
await CapacitorNfc.stopScanning();

Scrive i record NDEF forniti sul tag scoperto.

import { CapacitorNfc } from '@capgo/capacitor-nfc';
await CapacitorNfc.write({} as WriteTagOptions);

Tenta di cancellare l'ultima etichetta scoperta scrivendo un messaggio NDEF vuoto.

import { CapacitorNfc } from '@capgo/capacitor-nfc';
await CapacitorNfc.erase();

Tenta di rendere l'ultima etichetta scoperta lettura sola.

import { CapacitorNfc } from '@capgo/capacitor-nfc';
await CapacitorNfc.makeReadOnly();

Condivide un messaggio NDEF con un altro dispositivo tramite peer-to-peer (solo Android).

import { CapacitorNfc } from '@capgo/capacitor-nfc';
await CapacitorNfc.share({} as ShareTagOptions);

Smette di condividere il messaggio NDEF precedentemente fornito (solo Android).

import { CapacitorNfc } from '@capgo/capacitor-nfc';
await CapacitorNfc.unshare();

Restituisce lo stato attuale dell'adattatore NFC.

import { CapacitorNfc } from '@capgo/capacitor-nfc';
await CapacitorNfc.getStatus();

Apre la pagina delle impostazioni del sistema dove l'utente può abilitare l'NFC.

import { CapacitorNfc } from '@capgo/capacitor-nfc';
await CapacitorNfc.showSettings();

Controlla se il dispositivo dispone di supporto hardware NFC.

Restituisce true se il dispositivo dispone di hardware NFC, indipendentemente dalla situazione in cui si trova l'NFC (abilitato o disabilitato). Restituisce false se il dispositivo non dispone di hardware NFC.

Utilizza questo metodo per determinare se mostrare le funzionalità NFC nella UI del tuo app. Per verificare se l'NFC è attualmente abilitato, utilizza getStatus().

import { CapacitorNfc } from '@capgo/capacitor-nfc';
await CapacitorNfc.isSupported();

Opzioni che controllano il comportamento di .

export interface StartScanningOptions {
/**
* iOS-only: closes the NFC session automatically after the first successful tag read.
* Defaults to `true`.
*/
invalidateAfterFirstRead?: boolean;
/**
* iOS-only: custom message displayed in the NFC system sheet while scanning.
*/
alertMessage?: string;
/**
* iOS-only: session type to use for NFC scanning.
* - `'ndef'`: Uses NFCNDEFReaderSession (default). Only detects NDEF-formatted tags.
* - `'tag'`: Uses NFCTagReaderSession. Detects both NDEF and non-NDEF tags (e.g., raw MIFARE tags).
* Allows reading UID from unformatted tags.
* **Requires** the `Near Field Communication Tag Reader Session Formats` entitlement
* in your app with the `TAG` format included. Without it the session will fail to
* start and the promise will reject with a `NO_NFC` error code.
* Defaults to `'ndef'` for backward compatibility.
*/
iosSessionType?: 'ndef' | 'tag';
/**
* Android-only: raw flags passed to `NfcAdapter.enableReaderMode`.
* Defaults to enabling all tag types with skipping NDEF checks.
*/
androidReaderModeFlags?: number;
}

Opzioni utilizzate quando si scrive un messaggio NDEF sul tag corrente.

export interface WriteTagOptions {
/**
* Array of records that compose the NDEF message to be written.
*/
records: NdefRecord[];
/**
* When `true`, the plugin attempts to format NDEF-formattable tags before writing.
* Defaults to `true`.
*/
allowFormat?: boolean;
}

Opzioni utilizzate quando si condivide un messaggio NDEF con un altro dispositivo utilizzando il modo Android Beam / P2P.

export interface ShareTagOptions {
records: NdefRecord[];
}

Possibili stati del lettore NFC restituiti da .

export type NfcStatus = 'NFC_OK' | 'NO_NFC' | 'NFC_DISABLED' | 'NDEF_PUSH_DISABLED';

Evento di scoperta NFC generico inviato dal plugin.

export interface NfcEvent {
type: NfcEventType;
tag: NfcTag;
}

Evento emesso ogni volta che cambia la disponibilità del lettore NFC.

export interface NfcStateChangeEvent {
status: NfcStatus;
enabled: boolean;
}

Struttura JSON che rappresenta un singolo registro NDEF.

export interface NdefRecord {
/**
* Type Name Format identifier.
*/
tnf: number;
/**
* Type field expressed as an array of byte values.
*/
type: number[];
/**
* Record identifier expressed as an array of byte values.
*/
id: number[];
/**
* Raw payload expressed as an array of byte values.
*/
payload: number[];
}

Descrive il tipo di scoperta NFC che è accaduta.

export type NfcEventType = 'tag' | 'ndef' | 'ndef-mime' | 'ndef-formatable';

Rappresentazione delle informazioni complete dell'etichetta restituite dai layer nativi.

export interface NfcTag {
/**
* Raw identifier bytes for the tag.
*/
id?: number[];
/**
* List of Android tech strings (e.g. `android.nfc.tech.Ndef`).
*/
techTypes?: string[];
/**
* Human readable tag type when available (e.g. `NFC Forum Type 2`, `MIFARE Ultralight`).
*/
type?: string | null;
/**
* Maximum writable size in bytes for tags that expose NDEF information.
*/
maxSize?: number | null;
/**
* Indicates whether the tag can be written to.
*/
isWritable?: boolean | null;
/**
* Indicates whether the tag can be permanently locked.
*/
canMakeReadOnly?: boolean | null;
/**
* Array of NDEF records discovered on the tag.
*/
ndefMessage?: NdefRecord[] | null;
}

Questa pagina è generata dal plugin e viene sincronizzata con il repository originale. src/definitions.tsRiavvia la sincronizzazione quando le informazioni pubbliche API cambiano nell'origine.