はじめに
インストールステップとこのプラグインの全てのマークダウンガイドを含む設定プロンプトをコピー
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.
インストール
「インストール」というセクションbun add @capgo/capacitor-nfcbunx cap syncインポート
「インポート」というセクションimport { CapacitorNfc } from '@capgo/capacitor-nfc';APIの概要
「APIの概要」タイトルのセクションstartScanning
「startScanning」タイトルのセクションNFCタグを待ち受け始める。
import { CapacitorNfc } from '@capgo/capacitor-nfc';
await CapacitorNfc.startScanning();stopScanning
「stopScanning」タイトルのセクション進行中のNFCスキャニングセッションを停止します。
import { CapacitorNfc } from '@capgo/capacitor-nfc';
await CapacitorNfc.stopScanning();クリップボードにコピー
import { CapacitorNfc } from '@capgo/capacitor-nfc';
await CapacitorNfc.write({} as WriteTagOptions);erase
消去最後に発見されたタグを消去するために空のNDEFメッセージを書き込もうとします。
import { CapacitorNfc } from '@capgo/capacitor-nfc';
await CapacitorNfc.erase();makeReadOnly
読み取り専用化最後に発見されたタグを読み取り専用にします。
import { CapacitorNfc } from '@capgo/capacitor-nfc';
await CapacitorNfc.makeReadOnly();share
共有Android専用のペアツーペアでNDEFメッセージを共有します。
import { CapacitorNfc } from '@capgo/capacitor-nfc';
await CapacitorNfc.share({} as ShareTagOptions);unshare
共有停止Android専用のペアツーペアで提供されたNDEFメッセージの共有を停止します。
import { CapacitorNfc } from '@capgo/capacitor-nfc';
await CapacitorNfc.unshare();getStatus
getStatusのセクション現在のNFCアダプタの状態を取得します。
import { CapacitorNfc } from '@capgo/capacitor-nfc';
await CapacitorNfc.getStatus();showSettings
showSettingsのセクションNFCを有効にするためのシステム設定画面を開きます。
import { CapacitorNfc } from '@capgo/capacitor-nfc';
await CapacitorNfc.showSettings();isSupported
isSupportedのセクションNFCハードウェアのサポートをチェックします。
NFCハードウェアが存在する場合、NFCが有効または無効であるかは関係なく、trueを返します。 true NFCハードウェアが存在しない場合、falseを返します。 false このメソッドを使用して、NFC機能を表示するかどうかを決定します。NFCが現在有効かどうかを確認するには、
__CAPGO_KEEP_0__ getStatus().
import { CapacitorNfc } from '@capgo/capacitor-nfc';
await CapacitorNfc.isSupported();型の参照
型の参照StartScanningOptions
タグのスキャンを開始するオプションの動作を制御するオプション
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
タグにNDEFメッセージを書き込む場合に使用されるオプションクリップボードにコピー
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
クリップボードにコピータグにNDEFメッセージを共有する場合に使用されるオプション
export interface ShareTagOptions { records: NdefRecord[];}NfcStatus
NfcStatusセクション.から返される可能なNFCアダプタの状態
export type NfcStatus = 'NFC_OK' | 'NO_NFC' | 'NFC_DISABLED' | 'NDEF_PUSH_DISABLED';NfcEvent
NfcEventセクションプラグインによってディスパッチされる一般的なNFC発見イベント
export interface NfcEvent { type: NfcEventType; tag: NfcTag;}NfcStateChangeEvent
NfcStateChangeEventセクションNFCアダプタの利用可能性が変更されたときに発行されるイベント
export interface NfcStateChangeEvent { status: NfcStatus; enabled: boolean;}NdefRecord
NdefRecordセクション1つのNDEFレコードを表すJSON構造
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
NfcEventTypeのセクションNFCの発見の種類を表すイベント
export type NfcEventType = 'tag' | 'ndef' | 'ndef-mime' | 'ndef-formatable';NfcTag
NfcTagのセクションネイティブ層から返されたタグ情報の完全な表現
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;}真実の源
真実の源のセクションこのページはプラグインの src/definitions.ts公開APIがアップストリームで変更されたときに再度Syncを実行してください。