Getting Started
このプラグインのインストール手順と完全なマークダウンガイドを含むセットアップコマンドをコピーしてください。
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.
インストール
「インストール」のセクションAI-Assisted セットアップを使用してプラグインをインストールできます。次のコマンドを使用して、Capgo スキルをAIツールに追加します。
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-plugins次のプロンプトを使用してください。
Use the `capacitor-plugins` skill from `Cap-go/capgo-skills` to install the `@capgo/capacitor-nfc` plugin in my project.Manual セットアップを使用する場合は、次のコマンドを実行してプラグインをインストールし、以下のプラットフォーム固有の指示に従ってください。
bun add @capgo/capacitor-nfcbunx cap syncインポート
「インポート」のセクションimport { CapacitorNfc } from '@capgo/capacitor-nfc';API の概要
Section titled “API API”startScanning
Section titled “__CAPGO_KEEP_0__”NFCタグを検出する準備ができました。
import { CapacitorNfc } from '@capgo/capacitor-nfc';
await CapacitorNfc.startScanning();stopScanning
Section titled “__CAPGO_KEEP_0__”NFCスキャニングセッションを停止します。
import { CapacitorNfc } from '@capgo/capacitor-nfc';
await CapacitorNfc.stopScanning();最後に検出されたタグにNDEFレコードを書き込みます。
import { CapacitorNfc } from '@capgo/capacitor-nfc';
await CapacitorNfc.write({} as WriteTagOptions);最後に検出されたタグを空のNDEFメッセージで消去します。
import { CapacitorNfc } from '@capgo/capacitor-nfc';
await CapacitorNfc.erase();makeReadOnly
「makeReadOnly」セクション最後に発見されたタグを読み取り専用にします。
import { CapacitorNfc } from '@capgo/capacitor-nfc';
await CapacitorNfc.makeReadOnly();share
「share」セクションAndroid専用のペア対称通信を使用して、NDEF メッセージを別のデバイスに共有します。
import { CapacitorNfc } from '@capgo/capacitor-nfc';
await CapacitorNfc.share({} as ShareTagOptions);unshare
「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ハードウェアをサポートしているかどうかを確認します。
戻り値 true デバイスにNFCハードウェアが存在する場合、NFCが現在有効または無効であるかは関係なくtrueを返します。デバイスにNFCハードウェアが存在しない場合、falseを返します。 false このメソッドを使用して、NFC機能が表示されるべきかどうかを判断します。NFCが現在有効かどうかを確認するには、
クリップボードにコピー getStatus().
import { CapacitorNfc } from '@capgo/capacitor-nfc';
await CapacitorNfc.isSupported();Type Reference
種類の参照StartScanningOptions
スキャンを開始するオプション__CAPGO_KEEP_0__の動作を制御するオプション
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
コピーNFCアダプタの状態
export interface ShareTagOptions { records: NdefRecord[];}NfcStatus
__CAPGO_KEEP_0____CAPGO_KEEP_0__
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
Nfcタグネイティブレイヤーから返されるフルタグ情報の表現
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.tsAPI がアップストリームで変更された場合に再度同期を実行してください。
Getting Started から続けて
Section titled “Getting Started から続けて”Capacitor を使用している場合 Getting Started ダッシュボードとAPIの作業を計画するには、 Using @capgo/capacitor-nfc Using @capgo/capacitor-nfcのネイティブ機能 APIの概要 APIの概要の実装詳細 導入 導入の実装詳細 APIのキー APIのキーと実装詳細 デバイス デバイスの実装詳細