メニューに進む

Getting Started

ターミナル画面
bun add @capgo/capacitor-nfc
bunx cap sync
import { CapacitorNfc } from '@capgo/capacitor-nfc';

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

erase

erase

最後に発見したタグを空の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();

showSettings

showSettings

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

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

isSupported

isSupported

デバイスにNFCハードウェアが搭載されているかどうかを確認します。

戻り値 true デバイスにNFCハードウェアが搭載されている場合、NFCが有効または無効でも関係ありません。 false 戻り値

デバイスにNFCハードウェアが搭載されていない場合。 getStatus().

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

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

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

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

export interface ShareTagOptions {
records: NdefRecord[];
}

__CAPGO_KEEP_0__によって返されるNFCアダプターの状態

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

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

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

NFCアダプタの利用可能性が変更されたときに発行されるイベント。

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

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

発見された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から続けて

Getting Started

計画用ダッシュボードと__CAPGO_KEEP_0__の操作を行う場合に使用している場合 Getting Started ダッシュボードとAPIの操作を計画するには接続してください @capgo/capacitor-nfc @capgo/capacitor-nfc API の概要 API の実装詳細 導入 __CAPGO_KEEP_0__ のキー API の実装詳細、そして for the implementation detail in API Keys, and __CAPGO_KEEP_0__ の実装詳細 ページを編集