__CAPGO_KEEP_2__

スタートガイド

GitHub

AI-Assisted セットアップを使用してプラグインをインストールできます。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-nfc
bunx cap sync
import { CapacitorNfc } from '@capgo/capacitor-nfc';

NFCタグを待ち受けている

import { CapacitorNfc } from '@capgo/capacitor-nfc';
await CapacitorNfc.startScanning();

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();

最後に発見されたタグを読み取り専用にします。

import { CapacitorNfc } from '@capgo/capacitor-nfc';
await CapacitorNfc.makeReadOnly();

Androidのみで、NDEFメッセージを別のデバイスに共有します。

import { CapacitorNfc } from '@capgo/capacitor-nfc';
await CapacitorNfc.share({} as ShareTagOptions);

Androidのみで、以前提供されたNDEFメッセージの共有を停止します。

import { CapacitorNfc } from '@capgo/capacitor-nfc';
await CapacitorNfc.unshare();

現在のNFCアダプタの状態を取得します。

import { CapacitorNfc } from '@capgo/capacitor-nfc';
await CapacitorNfc.getStatus();

NFCを有効にする設定画面を開きます。

import { CapacitorNfc } from '@capgo/capacitor-nfc';
await CapacitorNfc.showSettings();

デバイスがNFCハードウェアをサポートしているかどうかを確認します。

このメソッドを使用して、NFC機能を表示するかどうかを判断します。NFCが現在有効かどうかを確認する場合は true NFCハードウェアがデバイスに存在する場合、NFCが有効か無効かは関係ありません。NFCハードウェアが存在しない場合 false NFCハードウェアが存在しない場合

NFCハードウェアが存在しない場合 getStatus().

import { CapacitorNfc } from '@capgo/capacitor-nfc';
await CapacitorNfc.isSupported();

タイプ リファレンス

タイプ リファレンス

タグ スキャン オプション

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;
}

タグ共有オプション

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;
}

タグ共有オプション

export interface ShareTagOptions {
records: NdefRecord[];
}

NFCアダプターが返す可能な状態

export type NfcStatus = 'NFC_OK' | 'NO_NFC' | 'NFC_DISABLED' | 'NDEF_PUSH_DISABLED';

プラグインが発行する一般的なNFC検出イベント

export interface NfcEvent {
type: NfcEventType;
tag: NfcTag;
}

コピー

export interface NfcStateChangeEvent {
status: NfcStatus;
enabled: boolean;
}

コピー

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[];
}

NFCの発見の種類を表すイベントタイプです。

export type NfcEventType = 'tag' | 'ndef' | 'ndef-mime' | 'ndef-formatable';

ネイティブレイヤーから返されたタグ情報の完全な表現です。

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__がアップストリームで変更されたら、再度Syncを実行してください。 src/definitions.ts. Re-run the sync when the public API changes upstream.

NfcTagのセクション

クリップボードにコピー

Capgoを使用している場合 Getting Started APIを使用してダッシュボードとAPIの操作を計画する capgoの@capgo/capacitor-nfcを使用 for the native capability in Using @capgo/capacitor-nfc, APIの実装詳細 for the implementation detail in API Overview, __CAPGO_KEEP_0__の実装詳細 __CAPGO_KEEP_0__のキー APIの実装詳細 for the implementation detail in API Keys, and __CAPGO_KEEP_0__ デバイスの実装詳細について。