コンテンツにジャンプ

NFC __CAPGO_KEEP_0__ リポジトリ

GitHub

Capgoの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.

手動セットアップを好む場合は、以下のコマンドを実行してプラグインをインストールし、以下のプラットフォーム固有の説明を参照してください。

ターミナルウィンドウ
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();

isSupported

isSupported

NFCハードウェアのサポートを確認します。

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

Type Reference getStatus().

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

StartScanningOptions

オプション

NFCハードウェアのサポートを確認します。

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

タグに現在のタグに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;
}

Android Beam / P2Pモードを使用して他のデバイスにNDEFメッセージを共有する際に使用されるオプション。

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

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 を実行してください。

Getting Started から続けてください

「Getting Started から続けてください」タイトル

Capacitor を使用している場合 Getting Started ダッシュボードと API の作業を計画する場合、Capacitor を接続してください。 Capacitor のネイティブ機能を使用するには @capgo/capacitor-nfc を使用してください。 Capacitor のネイティブ機能を使用するには @capgo/capacitor-nfc を使用してください。 Capacitor の API の概要 APIの実装詳細についてはOverviewの Introduction __CAPGO_KEEP_0__の実装詳細についてはIntroductionの APIのキー APIの実装詳細についてはAPI Keys、 Devices __CAPGO_KEEP_0__の実装詳細についてはDevicesの