Getting Started
Salin prompt pengaturan dengan langkah instalasi dan panduan markdown lengkap untuk plugin ini.
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.
Pasang
Bagian berjudul “Pasang”Anda dapat menggunakan Setup yang Dibantu AI kami untuk menginstal plugin. Tambahkan Capgo kemampuan ke alat AI Anda menggunakan perintah berikut:
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-pluginsLalu gunakan prompt berikut:
Use the `capacitor-plugins` skill from `Cap-go/capgo-skills` to install the `@capgo/capacitor-nfc` plugin in my project.Jika Anda lebih suka Setup Manual, instal plugin dengan menjalankan perintah-perintah berikut dan ikuti instruksi spesifik platform di bawah:
bun add @capgo/capacitor-nfcbunx cap syncimport { CapacitorNfc } from '@capgo/capacitor-nfc';API Ringkasan
Bagian berjudul “API Pengantar”startScanning
Bagian berjudul “startScanning”Mendengarkan tag NFC.
import { CapacitorNfc } from '@capgo/capacitor-nfc';
await CapacitorNfc.startScanning();stopScanning
Bagian berjudul “stopScanning”Menghentikan sesi pencarian NFC yang sedang berlangsung.
import { CapacitorNfc } from '@capgo/capacitor-nfc';
await CapacitorNfc.stopScanning();Menulis rekaman NDEF yang disediakan ke tag terakhir yang ditemukan.
import { CapacitorNfc } from '@capgo/capacitor-nfc';
await CapacitorNfc.write({} as WriteTagOptions);Mencoba menghapus tag terakhir yang ditemukan dengan menulis pesan NDEF kosong.
import { CapacitorNfc } from '@capgo/capacitor-nfc';
await CapacitorNfc.erase();makeReadOnly
Bagian berjudul “makeReadOnly”Mencoba membuat tag terakhir yang ditemukan tidak dapat diedit.
import { CapacitorNfc } from '@capgo/capacitor-nfc';
await CapacitorNfc.makeReadOnly();Mengirimkan pesan NDEF ke perangkat lain melalui peer-to-peer (hanya Android).
import { CapacitorNfc } from '@capgo/capacitor-nfc';
await CapacitorNfc.share({} as ShareTagOptions);unshare
Bagian berjudul “unshare”Menghentikan pengiriman pesan NDEF sebelumnya (hanya Android).
import { CapacitorNfc } from '@capgo/capacitor-nfc';
await CapacitorNfc.unshare();getStatus
Bagian berjudul “getStatus”Mengembalikan status adapter NFC saat ini.
import { CapacitorNfc } from '@capgo/capacitor-nfc';
await CapacitorNfc.getStatus();showSettings
Bagian berjudul “tampilkanPengaturan”Membuka halaman pengaturan sistem di mana pengguna dapat mengaktifkan NFC.
import { CapacitorNfc } from '@capgo/capacitor-nfc';
await CapacitorNfc.showSettings();isSupported
Bagian berjudul “dapatDitunjang”Mengecek apakah perangkat memiliki dukungan perangkat keras NFC.
Kembali true Jika perangkat memiliki perangkat keras NFC, terlepas dari
apakah NFC saat ini diaktifkan atau dinonaktifkan. Kembali false Jika perangkat tidak memiliki perangkat keras NFC.
Gunakan metode ini untuk menentukan apakah fitur NFC harus ditampilkan di UI aplikasi Anda. Untuk mengecek apakah NFC saat ini diaktifkan, gunakan getStatus().
import { CapacitorNfc } from '@capgo/capacitor-nfc';
await CapacitorNfc.isSupported();Referensi Tipe
Referensi TipeStartScanningOptions
Opsi Mulai MembacaOpsi Mengontrol perilaku .
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
Opsi Menulis TandaOpsi yang digunakan ketika menulis pesan NDEF pada tag saat ini.
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
Opsi Berbagi TagOpsi yang digunakan ketika berbagi pesan NDEF dengan perangkat lain menggunakan Android Beam / P2P mode.
export interface ShareTagOptions { records: NdefRecord[];}NfcStatus
Status NFCStatus adapter NFC yang dapat dikembalikan oleh .
export type NfcStatus = 'NFC_OK' | 'NO_NFC' | 'NFC_DISABLED' | 'NDEF_PUSH_DISABLED';NfcEvent
Bagian berjudul “NfcEvent”Event NFC umum yang diterbitkan oleh plugin.
export interface NfcEvent { type: NfcEventType; tag: NfcTag;}NfcStateChangeEvent
Bagian berjudul “NfcStateChangeEvent”Event yang diterbitkan ketika ketersediaan adapter NFC berubah.
export interface NfcStateChangeEvent { status: NfcStatus; enabled: boolean;}NdefRecord
Bagian berjudul “NdefRecord”Struktur JSON yang mewakili rekaman NDEF tunggal.
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
Bagian berjudul “NfcEventType”Tipe event yang menjelaskan jenis penemuan NFC yang terjadi.
export type NfcEventType = 'tag' | 'ndef' | 'ndef-mime' | 'ndef-formatable';NfcTag
Bagian berjudul “NfcTag”Informasi tag penuh yang dikembalikan oleh 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;}Sumber Kebenaran
Bagian berjudul “Sumber Kebenaran”Halaman ini dihasilkan dari plugin’s src/definitions.ts. Re-run sync ketika API publik berubah secara upstream.
Teruskan dari Getting Started
Bagian berjudul “Teruskan dari Getting Started”Jika Anda menggunakan Getting Started Untuk merencanakan dashboard dan API operasi, hubungkannya dengan Menggunakan @capgo/capacitor-nfc Untuk kemampuan asli dalam Menggunakan @capgo/capacitor-nfc, Ringkasan API Untuk detail implementasi dalam Ringkasan API, Pendahuluan Untuk detail implementasi dalam Pendahuluan, Kunci API Untuk detail implementasi dalam Kunci API, dan Perangkat Untuk detail implementasi dalam Perangkat.