はじめに
このプラグインのインストール手順とフル マークダウン ガイドを含むセットアップの質問をコピーします。
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アシストセットアップを使用してプラグインをインストールできます。AIツールに Capgo スキルを追加するには、以下のコマンドを実行してください。
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 オーバービュー
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();write
writeのセクション最後に発見されたタグにNDEFレコードを書き込む
import { CapacitorNfc } from '@capgo/capacitor-nfc';
await CapacitorNfc.write({} as WriteTagOptions);最後に発見されたタグを消去するために空のNDEFメッセージを書き込もうとします。
import { CapacitorNfc } from '@capgo/capacitor-nfc';
await CapacitorNfc.erase();makeReadOnly
Section titled “makeReadOnly”最後に発見されたタグを読み取り専用にします。
import { CapacitorNfc } from '@capgo/capacitor-nfc';
await CapacitorNfc.makeReadOnly();Androidのみで、別のデバイスにNDEFメッセージを共有します。
import { CapacitorNfc } from '@capgo/capacitor-nfc';
await CapacitorNfc.share({} as ShareTagOptions);unshare
Section titled “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 デバイスにNFCハードウェアが存在する場合、NFCが有効かどうかに関係なく、NFCハードウェアが存在する場合を返します。 false デバイスにNFCハードウェアが存在しない場合を返します。
デバイスにNFCハードウェアが存在する場合、NFCが有効かどうかに関係なく、NFCハードウェアが存在する場合を返します。NFCハードウェアが存在しない場合を返します。 getStatus().
import { CapacitorNfc } from '@capgo/capacitor-nfc';
await CapacitorNfc.isSupported();型の参照
「型の参照」のセクションStartScanningOptions
「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
「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
「ShareTagOptions」のセクションAndroid Beam / P2P モードで 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
NfcStateChangeEventNFCアダプタの利用可能性が変更されたときに発行されるイベントです。
export interface NfcStateChangeEvent { status: NfcStatus; enabled: boolean;}NdefRecord
NdefRecord1つの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
NfcEventTypeNFC発生イベントの種類を表す
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;}真実の源
このページはプラグインのパブリック__CAPGO_KEEP_0__がアップストリームで変更された場合に再度同期を実行してください。 src/definitions.ts. Re-run the sync when the public API changes upstream.
始めから
始めからCapgoを使用している場合 はじめに ダッシュボードとAPIの操作を計画するには、 Using @capgo/capacitor-nfc for the native capability in Using @capgo/capacitor-nfc, CapgoのAPIの概要 CapgoのAPIの概要で実装の詳細 はじめに はじめにで実装の詳細 CapgoのAPIのキー CapgoのAPIのキーで実装の詳細 デバイス デバイスの実装詳細について。