Getting Started
Copiez un prompt de configuration avec les étapes d'installation et la guide markdown complet pour ce 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.
Installer
Section intitulée « Installer »Vous pouvez utiliser notre configuration assistée par l'IA pour installer le plugin. Ajoutez les Capgo compétences à votre outil IA en utilisant la commande suivante :
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-pluginsUtilisez ensuite la prompt suivante :
Use the `capacitor-plugins` skill from `Cap-go/capgo-skills` to install the `@capgo/capacitor-nfc` plugin in my project.Si vous préférez la configuration manuelle, installez le plugin en exécutant les commandes suivantes et suivez les instructions spécifiques à la plateforme ci-dessous :
bun add @capgo/capacitor-nfcbunx cap syncImporter
Section intitulée « Importer »import { CapacitorNfc } from '@capgo/capacitor-nfc';API Vue d'ensemble
Section intitulée « API Vue d'ensemble »startScanning
Section intitulée « startScanning »Ecoute les balises NFC.
import { CapacitorNfc } from '@capgo/capacitor-nfc';
await CapacitorNfc.startScanning();stopScanning
Section intitulée “stopScanning”Arrête la session de balayage NFC en cours.
import { CapacitorNfc } from '@capgo/capacitor-nfc';
await CapacitorNfc.stopScanning();Écrit les enregistrements NDEF fournis dans le dernier tag découvert.
import { CapacitorNfc } from '@capgo/capacitor-nfc';
await CapacitorNfc.write({ records: [ { tnf: 1, type: [1], id: [1], payload: [1], }, ],});Essaye d'effacer le dernier tag découvert en écrivant un message NDEF vide.
import { CapacitorNfc } from '@capgo/capacitor-nfc';
await CapacitorNfc.erase();makeReadOnly
Section intitulée “makeReadOnly”Essaye de rendre le dernier tag découvert en lecture seule.
import { CapacitorNfc } from '@capgo/capacitor-nfc';
await CapacitorNfc.makeReadOnly();Partage un message NDEF avec un autre appareil via peer-to-peer (seulement Android).
import { CapacitorNfc } from '@capgo/capacitor-nfc';
await CapacitorNfc.share({ records: [ { tnf: 1, type: [1], id: [1], payload: [1], }, ],});Arrête de partager le message NDEF précédemment fourni (seulement Android).
import { CapacitorNfc } from '@capgo/capacitor-nfc';
await CapacitorNfc.unshare();getStatus
Section intitulée “obtenir l’état”Renvoie le statut actuel de l’adaptateur NFC.
import { CapacitorNfc } from '@capgo/capacitor-nfc';
const result = await CapacitorNfc.getStatus();console.log(result);showSettings
Section intitulée “afficher les paramètres”Ouvre la page de paramètres système où l’utilisateur peut activer l’NFC.
import { CapacitorNfc } from '@capgo/capacitor-nfc';
await CapacitorNfc.showSettings();isSupported
Titre de la section « isSupported »Vérifie si le dispositif dispose d'un support matériel NFC.
Retourne true Si un matériel NFC est présent sur le dispositif, qu'il soit actif ou inactif. false si le dispositif n'a pas de matériel NFC.
Vérifiez si les fonctionnalités NFC doivent être affichées dans l'interface utilisateur de votre application. Pour vérifier si NFC est actuellement activé, utilisez getStatus().
import { CapacitorNfc } from '@capgo/capacitor-nfc';
const result = await CapacitorNfc.isSupported();console.log(result);Référence de type
Titre de la section « Référence de type »StartScanningOptions
Options de démarrage de balayageOptions contrôlant le comportement de .
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
Options d'écriture de tagOptions utilisées lors de l'écriture d'un message NDEF sur la tag actuelle.
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
Option de partage de TagParamètres utilisés lors de la partage d'un message NDEF avec un autre appareil en utilisant Android Beam / P2P.
export interface ShareTagOptions { records: NdefRecord[];}NfcStatus
Section intitulée “État NFC”États possibles de l'adaptateur NFC retournés par .
export type NfcStatus = 'NFC_OK' | 'NO_NFC' | 'NFC_DISABLED' | 'NDEF_PUSH_DISABLED';Événement de découverte NFC générique diffusé par le plugin.
export interface NfcEvent { type: NfcEventType; tag: NfcTag;}NfcStateChangeEvent
Événement de changement d'état NFCÉvénement émis chaque fois que la disponibilité de l'adaptateur NFC change.
export interface NfcStateChangeEvent { status: NfcStatus; enabled: boolean;}Structure JSON représentant un seul enregistrement 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
Section intitulée « Type d'événement NFC »Type d'événement décrivant le type de découverte NFC qui s'est produite.
export type NfcEventType = 'tag' | 'ndef' | 'ndef-mime' | 'ndef-formatable';Représentation de l'information complète du tag retournée par les couches natives.
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;}Source De Vérité
Section intitulée « Source De Vérité »Cette page est générée à partir du plugin’s src/definitions.tsRexécutez la synchronisation lorsque les données publiques API changent en amont.
Continuez de la page d'accueil
Section intitulée « Continuez de la page d'accueil »Si vous utilisez Getting Started pour planifier le tableau de bord et les opérations API, connectez-l’avec Utilisez @capgo/capacitor-nfc pour la capacité native dans Utilisez @capgo/capacitor-nfc, API Overview Pour les détails d'implémentation dans API Vue d'ensemble. Introduction pour les détails d'implémentation dans l'Introduction. Clés API pour les détails d'implémentation dans les API clés, et Appareils pour les détails d'implémentation dans les appareils.