본문 바로가기

시작하기

GitHub

AI 지원 설정으로 플러그인을 설치할 수 있습니다. 다음 명령어로 AI 도구에 Capgo 스킬을 추가하세요:

터미널 창
bunx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-plugins

그다음 아래 prompt를 사용하세요:

Use the `capacitor-plugins` skill from `Cap-go/capgo-skills` to install the `@capgo/capacitor-nfc` plugin in my project.

Manual Setup을 선호한다면, 다음 명령어를 실행하여 플러그인을 설치하고 아래의 플랫폼별 지침을 따르세요:

터미널 창
bun add @capgo/capacitor-nfc
bunx cap sync
import { CapacitorNfc } from '@capgo/capacitor-nfc';
import { CapacitorNfc } from '@capgo/capacitor-nfc';
await CapacitorNfc.startScanning();
import { CapacitorNfc } from '@capgo/capacitor-nfc';
await CapacitorNfc.stopScanning();
import { CapacitorNfc } from '@capgo/capacitor-nfc';
await CapacitorNfc.write({
records: [
{
tnf: 1,
type: [1],
id: [1],
payload: [1],
},
],
});
  • 리스너: 화면이 unmount될 때 핸들을 제거하세요.
  • 네이티브 동기화: 실행 bunx cap sync 플러그인 업그레이드 후.
  • 단일 진실 공급원: 신뢰 src/definitions.ts GitHub 레포지토리에서.

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({
records: [
{
tnf: 1,
type: [1],
id: [1],
payload: [1],
},
],
});

빈 NDEF 메시지를 기록하여 마지막으로 감지된 태그를 삭제합니다.

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

마지막으로 감지된 태그를 읽기 전용으로 전환하려고 시도합니다.

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

P2P 방식을 통해 다른 기기와 NDEF 메시지를 공유합니다 (Android 전용).

import { CapacitorNfc } from '@capgo/capacitor-nfc';
await CapacitorNfc.share({
records: [
{
tnf: 1,
type: [1],
id: [1],
payload: [1],
},
],
});

이전에 제공한 NDEF 메시지 공유를 중단합니다 (Android 전용).

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

현재 NFC 어댑터 상태를 반환합니다.

import { CapacitorNfc } from '@capgo/capacitor-nfc';
const result = await CapacitorNfc.getStatus();
console.log(result);

사용자가 NFC를 활성화할 수 있는 시스템 설정 페이지를 엽니다.

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

기기가 NFC 하드웨어를 지원하는지 확인합니다.

반환값 true NFC 활성화 여부와 관계없이, 기기에 NFC 하드웨어가 있는 경우 true를 반환합니다. false 기기에 NFC 하드웨어가 없는 경우 false를 반환합니다.

앱 UI에 NFC 기능을 표시할지 결정할 때 이 메서드를 사용하세요. 현재 NFC가 활성화되어 있는지 확인하려면 getStatus().

import { CapacitorNfc } from '@capgo/capacitor-nfc';
const result = await CapacitorNfc.isSupported();
console.log(result);

.의 동작을 제어하는 옵션입니다.

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

NFC 어댑터의 사용 가능 상태가 변경될 때마다 발생하는 이벤트입니다.

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

단일 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';

네이티브 레이어에서 반환되는 전체 태그 정보의 표현입니다.

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에서 생성되었습니다. public API가 업스트림에서 변경되면 동기화를 다시 실행하세요.

사용 중인 경우 시작하기 대시보드와 API 운영을 계획하려면, 이를 다음 항목과 연결하세요: @capgo/capacitor-nfc 사용하기 @capgo/capacitor-nfc를 사용하여 네이티브 기능을 구현할 때, API 개요 API Overview의 구현 상세 내용은 소개 Introduction의 구현 상세 내용은 API 키 API Keys의 구현 세부 사항은, 디바이스 Devices의 구현 세부 사항은.