Iniziare
Copia un prompt di configurazione con i passaggi di installazione e la guida markdown completa per questo plugin.
Set up this Capacitor plugin in the project.
Use the package manager already used by the project.
Install these package(s): `@capgo/capacitor-nfc`
Run the required Capacitor sync/update step after installation.
Read this markdown guide for the full setup steps: https://raw.githubusercontent.com/Cap-go/website/refs/heads/main/apps/docs/src/content/docs/docs/plugins/nfc/getting-started.mdx
Use that guide for platform-specific steps, native file edits, permissions, config changes, imports, and usage setup.
If that guide references other docs pages, read them too.
Installa
Sezione intitolata “Installa”Puoi utilizzare la nostra configurazione assistita da AI per installare il plugin. Aggiungi le Capgo competenze al tuo strumento AI utilizzando il seguente comando:
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-pluginsPoi utilizza la seguente richiesta:
Use the `capacitor-plugins` skill from `Cap-go/capgo-skills` to install the `@capgo/capacitor-nfc` plugin in my project.Se preferisci la configurazione manuale, installa il plugin eseguendo i seguenti comandi e segui le istruzioni specifiche per la piattaforma riportate di seguito:
bun add @capgo/capacitor-nfcbunx cap syncImporta
Sezione intitolata “Importa”import { CapacitorNfc } from '@capgo/capacitor-nfc';API Panoramica
Sezione intitolata “API Panoramica”startScanning
Sezione intitolata “startScanning”Inizia ad ascoltare per le etichette NFC.
import { CapacitorNfc } from '@capgo/capacitor-nfc';
await CapacitorNfc.startScanning();stopScanning
Sezione intitolata “stopScanning”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 più recente.
import { CapacitorNfc } from '@capgo/capacitor-nfc';
await CapacitorNfc.write({} as WriteTagOptions);erase
EraseTenta di cancellare l'ultima tag scoperta scrivendo un messaggio NDEF vuoto.
import { CapacitorNfc } from '@capgo/capacitor-nfc';
await CapacitorNfc.erase();makeReadOnly
EraseTenta di rendere l'ultima tag scoperta in sola lettura.
import { CapacitorNfc } from '@capgo/capacitor-nfc';
await CapacitorNfc.makeReadOnly();share
CondividiCondivide un messaggio NDEF con un altro dispositivo tramite peer-to-peer (solo per Android).
import { CapacitorNfc } from '@capgo/capacitor-nfc';
await CapacitorNfc.share({} as ShareTagOptions);unshare
Non condividereSmette di condividere il messaggio NDEF precedentemente fornito (solo per Android).
import { CapacitorNfc } from '@capgo/capacitor-nfc';
await CapacitorNfc.unshare();getStatus
Sezione intitolata “getStatus”Restituisce lo stato attuale dell'adattatore NFC.
import { CapacitorNfc } from '@capgo/capacitor-nfc';
await CapacitorNfc.getStatus();showSettings
Sezione intitolata “mostraImpostazioni”Apre la pagina delle impostazioni del sistema dove l'utente può abilitare l'NFC.
import { CapacitorNfc } from '@capgo/capacitor-nfc';
await CapacitorNfc.showSettings();isSupported
Sezione intitolata “èSupportato”Controlla se il dispositivo dispone di supporto hardware NFC.
Restituisce true se il dispositivo dispone di hardware NFC, indipendentemente dal fatto che l'NFC sia attualmente abilitato o disabilitato. Restituisce false se il dispositivo non dispone di hardware NFC.
Utilizza questo metodo per determinare se le funzionalità NFC dovrebbero essere mostrate nella UI del tuo app. Per controllare se l'NFC è attualmente abilitato, utilizza getStatus().
import { CapacitorNfc } from '@capgo/capacitor-nfc';
await CapacitorNfc.isSupported();Riferimento al tipo
Sottosezione intitolata “Riferimento al tipo”StartScanningOptions
Sottosezione intitolata “StartScanningOptions”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;}WriteTagOptions
Sottosezione intitolata “WriteTagOptions”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;}ShareTagOptions
Sottosezione intitolata “ShareTagOptions”Opzioni utilizzate quando si condivide un messaggio NDEF con un altro dispositivo utilizzando il modo Android Beam / P2P.
export interface ShareTagOptions { records: NdefRecord[];}NfcStatus
Sezione intitolata “NfcStatus”Stati possibili dell'adattatore NFC restituiti da .
export type NfcStatus = 'NFC_OK' | 'NO_NFC' | 'NFC_DISABLED' | 'NDEF_PUSH_DISABLED';NfcEvent
Sezione intitolata “NfcEvent”Evento di scoperta NFC generico inviato dal plugin.
export interface NfcEvent { type: NfcEventType; tag: NfcTag;}NfcStateChangeEvent
Sezione intitolata “NfcStateChangeEvent”Evento emesso ogni volta che cambia la disponibilità dell'adattatore NFC.
export interface NfcStateChangeEvent { status: NfcStatus; enabled: boolean;}NdefRecord
Sezione intitolata “NdefRecord”Struttura JSON che rappresenta un singolo record 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[];}NfcEventType
Sezione intitolata “NfcEventType”Tipo di evento che descrive il tipo di scoperta NFC che è accaduta.
export type NfcEventType = 'tag' | 'ndef' | 'ndef-mime' | 'ndef-formatable';Rappresentazione delle informazioni complete del tag restituite dalle layer native.
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;}Punto di Riferimento
Sezione intitolata “Punto di Riferimento”Questa pagina è generata dal plugin’s src/definitions.tsRiavvia la sincronizzazione quando il pubblico API cambia in modo upstream.
Continua da qui Getting Started
Sezione intitolata “Continua da qui Getting Started”If you are using Iniziare per pianificare il dashboard e le operazioni API Usando @capgo/capacitor-nfc per la capacità nativa in Usando @capgo/capacitor-nfc API Overview per i dettagli di implementazione in API Overview Introduzione per i dettagli di implementazione in Introduzione API Keys per i dettagli di implementazione in API Keys, e Dispositivi per i dettagli di implementazione nei dispositivi.