はじめに
このプラグインのインストール手順と完全なMarkdownガイドを含むセットアッププロンプトをコピー
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.
インストール
「Install」セクションAIアシストセットアップを使ってプラグインをインストールできます。以下のコマンドで、お使いのAIツールに Capgo スキルを追加してください:
bunx 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.手動セットアップを希望する場合は、以下のコマンドでプラグインをインストールし、下記のプラットフォーム別の手順に従ってください:
bun add @capgo/capacitor-nfcbunx cap syncインポート
「Import」セクションimport { CapacitorNfc } from '@capgo/capacitor-nfc';クイックスタート
「Quick start」セクションimport { CapacitorNfc } from '@capgo/capacitor-nfc';
await CapacitorNfc.startScanning();例: stopScanning
「例: stopScanning」というセクションimport { CapacitorNfc } from '@capgo/capacitor-nfc';
await CapacitorNfc.stopScanning();例: write
「例: write」というセクションimport { CapacitorNfc } from '@capgo/capacitor-nfc';
await CapacitorNfc.write({ records: [ { tnf: 1, type: [1], id: [1], payload: [1], }, ],});よくある落とし穴
「Common pitfalls」セクション- リスナー: 画面のアンマウント時にハンドルを削除してください。
- ネイティブ同期: 実行
bunx cap syncプラグインのアップグレード後。 - 信頼できる情報源: 信頼する
src/definitions.tsGitHub リポジトリ内に
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({ records: [ { tnf: 1, type: [1], id: [1], payload: [1], }, ],});erase
「erase」セクション空のNDEFメッセージを書き込むことで、最後に検知したタグの消去を試みます。
import { CapacitorNfc } from '@capgo/capacitor-nfc';
await CapacitorNfc.erase();makeReadOnly
“makeReadOnly” セクション最後に検出されたタグを読み取り専用に設定します。
import { CapacitorNfc } from '@capgo/capacitor-nfc';
await CapacitorNfc.makeReadOnly();share
「share」セクションピア・ツー・ピア経由で別のデバイスと NDEF メッセージを共有します(Android のみ)。
import { CapacitorNfc } from '@capgo/capacitor-nfc';
await CapacitorNfc.share({ records: [ { tnf: 1, type: [1], id: [1], payload: [1], }, ],});unshare
“unshare” セクション以前に提供した NDEF メッセージの共有を停止します(Android のみ)。
import { CapacitorNfc } from '@capgo/capacitor-nfc';
await CapacitorNfc.unshare();getStatus
“getStatus” セクション現在の NFC アダプターの状態を返します。
import { CapacitorNfc } from '@capgo/capacitor-nfc';
const result = await CapacitorNfc.getStatus();console.log(result);showSettings
「showSettings」セクションユーザーがNFCを有効にできるシステム設定ページを開きます。
import { CapacitorNfc } from '@capgo/capacitor-nfc';
await CapacitorNfc.showSettings();isSupported
「isSupported」セクションデバイスがNFCハードウェアをサポートしているか確認します。
を返します true NFCが現在有効か無効かに関係なく、デバイスにNFCハードウェアが搭載されている場合は、次を返します: false デバイスにNFCハードウェアが搭載されていない場合。
アプリのUIにNFC機能を表示すべきかどうかを判断するには、このメソッドを使用してください。NFCが現在有効かどうかを確認するには、次を使用します: getStatus().
import { CapacitorNfc } from '@capgo/capacitor-nfc';
const result = await CapacitorNfc.isSupported();console.log(result);型リファレンス
「型リファレンス」セクション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
「NfcStateChangeEvent」セクションNFCアダプターの利用可能性が変化するたびに発行されるイベント。
export interface NfcStateChangeEvent { status: NfcStatus; enabled: boolean;}NdefRecord
「NdefRecord」セクション単一の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 を再実行してください。
Getting Started から続ける
「Getting Started からの続き」セクション以下を使用している場合: はじめに ダッシュボードと API の操作を計画するには、以下と連携してください @capgo/capacitor-nfc の使用方法 @capgo/capacitor-nfc でネイティブ機能を使用する場合、 API の概要 API Overview の実装の詳細については、 はじめに Introduction の実装の詳細については、 API キー API Keys の実装の詳細については、 デバイス Devices の実装の詳細については。