🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

@capgo/capacitor-nfc

Package Overview
Dependencies
Maintainers
1
Versions
41
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@capgo/capacitor-nfc - npm Package Compare versions

Comparing version
8.0.28
to
8.1.1
+32
-0
dist/docs.json

@@ -249,2 +249,11 @@ {

{
"name": "iosPollingOptions",
"tags": [],
"docs": "iOS-only: polling options to use for NFC scanning.\nDefaults to `['iso14443', 'iso15693', 'iso18092']` for backward compatibility.",
"complexTypes": [
"NfcIosPollingOption"
],
"type": "NfcIosPollingOption[] | undefined"
},
{
"name": "androidReaderModeFlags",

@@ -470,2 +479,25 @@ "tags": [],

{
"name": "NfcIosPollingOption",
"slug": "nfciospollingoption",
"docs": "iOS-specific polling options for NFC scanning sessions.\nThese options determine the type of tags that a reader session\nshould detect during a polling sequence.\n\n- 'iso14443': Polls for ISO 14443 tags\n- 'iso15693': Polls for ISO 15693 tags\n- 'iso18092': Polls for ISO 18092 tags\n- 'pace': Polls for PACE tags (available on iOS 16 and later)",
"types": [
{
"text": "'iso14443'",
"complexTypes": []
},
{
"text": "'iso15693'",
"complexTypes": []
},
{
"text": "'iso18092'",
"complexTypes": []
},
{
"text": "'pace'",
"complexTypes": []
}
]
},
{
"name": "NfcStatus",

@@ -472,0 +504,0 @@ "slug": "nfcstatus",

@@ -19,2 +19,13 @@ import type { PluginListenerHandle } from '@capacitor/core';

/**
* iOS-specific polling options for NFC scanning sessions.
* These options determine the type of tags that a reader session
* should detect during a polling sequence.
*
* - 'iso14443': Polls for ISO 14443 tags
* - 'iso15693': Polls for ISO 15693 tags
* - 'iso18092': Polls for ISO 18092 tags
* - 'pace': Polls for PACE tags (available on iOS 16 and later)
*/
export type NfcIosPollingOption = 'iso14443' | 'iso15693' | 'iso18092' | 'pace';
/**
* JSON structure representing a single NDEF record.

@@ -113,2 +124,7 @@ *

/**
* iOS-only: polling options to use for NFC scanning.
* Defaults to `['iso14443', 'iso15693', 'iso18092']` for backward compatibility.
*/
iosPollingOptions?: NfcIosPollingOption[];
/**
* Android-only: raw flags passed to `NfcAdapter.enableReaderMode`.

@@ -115,0 +131,0 @@ * Defaults to enabling all tag types with skipping NDEF checks.

+1
-1

@@ -1,1 +0,1 @@

{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["import type { PluginListenerHandle } from '@capacitor/core';\n\n/**\n * Possible NFC adapter states returned by {@link CapacitorNfcPlugin.getStatus}.\n *\n * Matches the constants provided by the original PhoneGap NFC plugin for\n * compatibility with existing applications.\n */\nexport type NfcStatus = 'NFC_OK' | 'NO_NFC' | 'NFC_DISABLED' | 'NDEF_PUSH_DISABLED';\n\n/**\n * Event type describing the kind of NFC discovery that happened.\n *\n * - `tag`: A generic NFC tag (no NDEF payload).\n * - `ndef`: A tag exposing an NDEF payload.\n * - `ndef-mime`: An NDEF tag that matched one of the MIME type filters.\n * - `ndef-formatable`: A tag that can be formatted to NDEF.\n */\nexport type NfcEventType = 'tag' | 'ndef' | 'ndef-mime' | 'ndef-formatable';\n\n/**\n * JSON structure representing a single NDEF record.\n *\n * Mirrors the data format returned by the legacy Cordova implementation and\n * uses integer arrays instead of strings to preserve the original payload\n * bytes.\n */\nexport interface NdefRecord {\n /**\n * Type Name Format identifier.\n */\n tnf: number;\n /**\n * Type field expressed as an array of byte values.\n */\n type: number[];\n /**\n * Record identifier expressed as an array of byte values.\n */\n id: number[];\n /**\n * Raw payload expressed as an array of byte values.\n */\n payload: number[];\n}\n\n/**\n * Representation of the full tag information returned by the native layers.\n *\n * Supports standard NFC Forum tags as well as MIFARE Ultralight cards (including\n * EV1 and NTAG variants). NDEF data is automatically extracted from MIFARE Ultralight\n * tags when available.\n */\nexport interface NfcTag {\n /**\n * Raw identifier bytes for the tag.\n */\n id?: number[];\n /**\n * List of Android tech strings (e.g. `android.nfc.tech.Ndef`).\n */\n techTypes?: string[];\n /**\n * Human readable tag type when available (e.g. `NFC Forum Type 2`, `MIFARE Ultralight`).\n */\n type?: string | null;\n /**\n * Maximum writable size in bytes for tags that expose NDEF information.\n */\n maxSize?: number | null;\n /**\n * Indicates whether the tag can be written to.\n */\n isWritable?: boolean | null;\n /**\n * Indicates whether the tag can be permanently locked.\n */\n canMakeReadOnly?: boolean | null;\n /**\n * Array of NDEF records discovered on the tag.\n */\n ndefMessage?: NdefRecord[] | null;\n}\n\n/**\n * Generic NFC discovery event dispatched by the plugin.\n */\nexport interface NfcEvent {\n type: NfcEventType;\n tag: NfcTag;\n}\n\n/**\n * Options controlling the behaviour of {@link CapacitorNfcPlugin.startScanning}.\n */\nexport interface StartScanningOptions {\n /**\n * iOS-only: closes the NFC session automatically after the first successful tag read.\n * Defaults to `true`.\n */\n invalidateAfterFirstRead?: boolean;\n /**\n * iOS-only: custom message displayed in the NFC system sheet while scanning.\n */\n alertMessage?: string;\n /**\n * iOS-only: session type to use for NFC scanning.\n * - `'ndef'`: Uses NFCNDEFReaderSession (default). Only detects NDEF-formatted tags.\n * - `'tag'`: Uses NFCTagReaderSession. Detects both NDEF and non-NDEF tags (e.g., raw MIFARE tags).\n * Allows reading UID from unformatted tags.\n * **Requires** the `Near Field Communication Tag Reader Session Formats` entitlement\n * in your app with the `TAG` format included. Without it the session will fail to\n * start and the promise will reject with a `NO_NFC` error code.\n * Defaults to `'ndef'` for backward compatibility.\n */\n iosSessionType?: 'ndef' | 'tag';\n /**\n * Android-only: raw flags passed to `NfcAdapter.enableReaderMode`.\n * Defaults to enabling all tag types with skipping NDEF checks.\n */\n androidReaderModeFlags?: number;\n}\n\n/**\n * Options used when writing an NDEF message on the current tag.\n */\nexport interface WriteTagOptions {\n /**\n * Array of records that compose the NDEF message to be written.\n */\n records: NdefRecord[];\n /**\n * When `true`, the plugin attempts to format NDEF-formattable tags before writing.\n * Defaults to `true`.\n */\n allowFormat?: boolean;\n}\n\n/**\n * Options used when sharing an NDEF message with another device using Android Beam / P2P mode.\n */\nexport interface ShareTagOptions {\n records: NdefRecord[];\n}\n\n/**\n * Event emitted whenever the NFC adapter availability changes.\n */\nexport interface NfcStateChangeEvent {\n status: NfcStatus;\n enabled: boolean;\n}\n\n/**\n * Public API surface for the Capacitor NFC plugin.\n *\n * The interface intentionally mirrors the behaviour of the reference PhoneGap\n * implementation to ease migration while embracing idiomatic Capacitor APIs.\n */\nexport interface CapacitorNfcPlugin {\n /**\n * Starts listening for NFC tags.\n */\n startScanning(options?: StartScanningOptions): Promise<void>;\n /**\n * Stops the ongoing NFC scanning session.\n */\n stopScanning(): Promise<void>;\n /**\n * Writes the provided NDEF records to the last discovered tag.\n */\n write(options: WriteTagOptions): Promise<void>;\n /**\n * Attempts to erase the last discovered tag by writing an empty NDEF message.\n */\n erase(): Promise<void>;\n /**\n * Attempts to make the last discovered tag read-only.\n */\n makeReadOnly(): Promise<void>;\n /**\n * Shares an NDEF message with another device via peer-to-peer (Android only).\n */\n share(options: ShareTagOptions): Promise<void>;\n /**\n * Stops sharing previously provided NDEF message (Android only).\n */\n unshare(): Promise<void>;\n /**\n * Returns the current NFC adapter status.\n */\n getStatus(): Promise<{ status: NfcStatus }>;\n /**\n * Opens the system settings page where the user can enable NFC.\n */\n showSettings(): Promise<void>;\n /**\n * Returns the version string baked into the native plugin.\n */\n getPluginVersion(): Promise<{ version: string }>;\n /**\n * Checks whether the device has NFC hardware support.\n *\n * Returns `true` if NFC hardware is present on the device, regardless of\n * whether NFC is currently enabled or disabled. Returns `false` if the\n * device does not have NFC hardware.\n *\n * Use this method to determine if NFC features should be shown in your\n * app's UI. To check if NFC is currently enabled, use `getStatus()`.\n */\n isSupported(): Promise<{ supported: boolean }>;\n\n addListener(eventName: 'nfcEvent', listenerFunc: (event: NfcEvent) => void): Promise<PluginListenerHandle>;\n addListener(\n eventName: 'tagDiscovered' | 'ndefDiscovered' | 'ndefMimeDiscovered' | 'ndefFormatableDiscovered',\n listenerFunc: (event: NfcEvent) => void,\n ): Promise<PluginListenerHandle>;\n addListener(\n eventName: 'nfcStateChange',\n listenerFunc: (event: NfcStateChangeEvent) => void,\n ): Promise<PluginListenerHandle>;\n}\n\nexport type { PluginListenerHandle } from '@capacitor/core';\n"]}
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["import type { PluginListenerHandle } from '@capacitor/core';\n\n/**\n * Possible NFC adapter states returned by {@link CapacitorNfcPlugin.getStatus}.\n *\n * Matches the constants provided by the original PhoneGap NFC plugin for\n * compatibility with existing applications.\n */\nexport type NfcStatus = 'NFC_OK' | 'NO_NFC' | 'NFC_DISABLED' | 'NDEF_PUSH_DISABLED';\n\n/**\n * Event type describing the kind of NFC discovery that happened.\n *\n * - `tag`: A generic NFC tag (no NDEF payload).\n * - `ndef`: A tag exposing an NDEF payload.\n * - `ndef-mime`: An NDEF tag that matched one of the MIME type filters.\n * - `ndef-formatable`: A tag that can be formatted to NDEF.\n */\nexport type NfcEventType = 'tag' | 'ndef' | 'ndef-mime' | 'ndef-formatable';\n\n/**\n * iOS-specific polling options for NFC scanning sessions.\n * These options determine the type of tags that a reader session\n * should detect during a polling sequence.\n *\n * - 'iso14443': Polls for ISO 14443 tags\n * - 'iso15693': Polls for ISO 15693 tags\n * - 'iso18092': Polls for ISO 18092 tags\n * - 'pace': Polls for PACE tags (available on iOS 16 and later)\n */\nexport type NfcIosPollingOption = 'iso14443' | 'iso15693' | 'iso18092' | 'pace';\n\n/**\n * JSON structure representing a single NDEF record.\n *\n * Mirrors the data format returned by the legacy Cordova implementation and\n * uses integer arrays instead of strings to preserve the original payload\n * bytes.\n */\nexport interface NdefRecord {\n /**\n * Type Name Format identifier.\n */\n tnf: number;\n /**\n * Type field expressed as an array of byte values.\n */\n type: number[];\n /**\n * Record identifier expressed as an array of byte values.\n */\n id: number[];\n /**\n * Raw payload expressed as an array of byte values.\n */\n payload: number[];\n}\n\n/**\n * Representation of the full tag information returned by the native layers.\n *\n * Supports standard NFC Forum tags as well as MIFARE Ultralight cards (including\n * EV1 and NTAG variants). NDEF data is automatically extracted from MIFARE Ultralight\n * tags when available.\n */\nexport interface NfcTag {\n /**\n * Raw identifier bytes for the tag.\n */\n id?: number[];\n /**\n * List of Android tech strings (e.g. `android.nfc.tech.Ndef`).\n */\n techTypes?: string[];\n /**\n * Human readable tag type when available (e.g. `NFC Forum Type 2`, `MIFARE Ultralight`).\n */\n type?: string | null;\n /**\n * Maximum writable size in bytes for tags that expose NDEF information.\n */\n maxSize?: number | null;\n /**\n * Indicates whether the tag can be written to.\n */\n isWritable?: boolean | null;\n /**\n * Indicates whether the tag can be permanently locked.\n */\n canMakeReadOnly?: boolean | null;\n /**\n * Array of NDEF records discovered on the tag.\n */\n ndefMessage?: NdefRecord[] | null;\n}\n\n/**\n * Generic NFC discovery event dispatched by the plugin.\n */\nexport interface NfcEvent {\n type: NfcEventType;\n tag: NfcTag;\n}\n\n/**\n * Options controlling the behaviour of {@link CapacitorNfcPlugin.startScanning}.\n */\nexport interface StartScanningOptions {\n /**\n * iOS-only: closes the NFC session automatically after the first successful tag read.\n * Defaults to `true`.\n */\n invalidateAfterFirstRead?: boolean;\n /**\n * iOS-only: custom message displayed in the NFC system sheet while scanning.\n */\n alertMessage?: string;\n /**\n * iOS-only: session type to use for NFC scanning.\n * - `'ndef'`: Uses NFCNDEFReaderSession (default). Only detects NDEF-formatted tags.\n * - `'tag'`: Uses NFCTagReaderSession. Detects both NDEF and non-NDEF tags (e.g., raw MIFARE tags).\n * Allows reading UID from unformatted tags.\n * **Requires** the `Near Field Communication Tag Reader Session Formats` entitlement\n * in your app with the `TAG` format included. Without it the session will fail to\n * start and the promise will reject with a `NO_NFC` error code.\n * Defaults to `'ndef'` for backward compatibility.\n */\n iosSessionType?: 'ndef' | 'tag';\n /**\n * iOS-only: polling options to use for NFC scanning.\n * Defaults to `['iso14443', 'iso15693', 'iso18092']` for backward compatibility.\n */\n iosPollingOptions?: NfcIosPollingOption[];\n /**\n * Android-only: raw flags passed to `NfcAdapter.enableReaderMode`.\n * Defaults to enabling all tag types with skipping NDEF checks.\n */\n androidReaderModeFlags?: number;\n}\n\n/**\n * Options used when writing an NDEF message on the current tag.\n */\nexport interface WriteTagOptions {\n /**\n * Array of records that compose the NDEF message to be written.\n */\n records: NdefRecord[];\n /**\n * When `true`, the plugin attempts to format NDEF-formattable tags before writing.\n * Defaults to `true`.\n */\n allowFormat?: boolean;\n}\n\n/**\n * Options used when sharing an NDEF message with another device using Android Beam / P2P mode.\n */\nexport interface ShareTagOptions {\n records: NdefRecord[];\n}\n\n/**\n * Event emitted whenever the NFC adapter availability changes.\n */\nexport interface NfcStateChangeEvent {\n status: NfcStatus;\n enabled: boolean;\n}\n\n/**\n * Public API surface for the Capacitor NFC plugin.\n *\n * The interface intentionally mirrors the behaviour of the reference PhoneGap\n * implementation to ease migration while embracing idiomatic Capacitor APIs.\n */\nexport interface CapacitorNfcPlugin {\n /**\n * Starts listening for NFC tags.\n */\n startScanning(options?: StartScanningOptions): Promise<void>;\n /**\n * Stops the ongoing NFC scanning session.\n */\n stopScanning(): Promise<void>;\n /**\n * Writes the provided NDEF records to the last discovered tag.\n */\n write(options: WriteTagOptions): Promise<void>;\n /**\n * Attempts to erase the last discovered tag by writing an empty NDEF message.\n */\n erase(): Promise<void>;\n /**\n * Attempts to make the last discovered tag read-only.\n */\n makeReadOnly(): Promise<void>;\n /**\n * Shares an NDEF message with another device via peer-to-peer (Android only).\n */\n share(options: ShareTagOptions): Promise<void>;\n /**\n * Stops sharing previously provided NDEF message (Android only).\n */\n unshare(): Promise<void>;\n /**\n * Returns the current NFC adapter status.\n */\n getStatus(): Promise<{ status: NfcStatus }>;\n /**\n * Opens the system settings page where the user can enable NFC.\n */\n showSettings(): Promise<void>;\n /**\n * Returns the version string baked into the native plugin.\n */\n getPluginVersion(): Promise<{ version: string }>;\n /**\n * Checks whether the device has NFC hardware support.\n *\n * Returns `true` if NFC hardware is present on the device, regardless of\n * whether NFC is currently enabled or disabled. Returns `false` if the\n * device does not have NFC hardware.\n *\n * Use this method to determine if NFC features should be shown in your\n * app's UI. To check if NFC is currently enabled, use `getStatus()`.\n */\n isSupported(): Promise<{ supported: boolean }>;\n\n addListener(eventName: 'nfcEvent', listenerFunc: (event: NfcEvent) => void): Promise<PluginListenerHandle>;\n addListener(\n eventName: 'tagDiscovered' | 'ndefDiscovered' | 'ndefMimeDiscovered' | 'ndefFormatableDiscovered',\n listenerFunc: (event: NfcEvent) => void,\n ): Promise<PluginListenerHandle>;\n addListener(\n eventName: 'nfcStateChange',\n listenerFunc: (event: NfcStateChangeEvent) => void,\n ): Promise<PluginListenerHandle>;\n}\n\nexport type { PluginListenerHandle } from '@capacitor/core';\n"]}

@@ -7,3 +7,3 @@ import Capacitor

public class NfcPlugin: CAPPlugin, CAPBridgedPlugin {
private let pluginVersion: String = "8.0.28"
private let pluginVersion: String = "8.1.1"

@@ -50,2 +50,24 @@ public let identifier = "NfcPlugin"

private func pollingOptions(_ requestedPollingOptions: JSArray) -> NFCTagReaderSession.PollingOption {
var pollingOptions: NFCTagReaderSession.PollingOption = []
for option in requestedPollingOptions {
guard let string = option as? String else {
continue
}
if string == "iso14443" {
pollingOptions.insert(.iso14443)
} else if string == "iso15693" {
pollingOptions.insert(.iso15693)
} else if string == "iso18092" {
pollingOptions.insert(.iso18092)
} else if string == "pace" {
if #available(iOS 16.0, *) {
pollingOptions.insert(.pace)
}
}
}
return pollingOptions
}
private func makeTagReaderSession(

@@ -94,2 +116,9 @@ pollingOptions: NFCTagReaderSession.PollingOption,

let requestedPollingOptions = call.getArray("iosPollingOptions", ["iso14443", "iso15693", "iso18092"])
let pollingOptions = self.pollingOptions(requestedPollingOptions)
guard sessionType != "tag" || !pollingOptions.isEmpty else {
call.reject("No valid polling options provided")
return
}
DispatchQueue.main.async {

@@ -116,3 +145,3 @@ // Invalidate any existing sessions

let session = self.makeTagReaderSession(
pollingOptions: [.iso14443, .iso15693, .iso18092],
pollingOptions: pollingOptions,
alertMessage: alertMessage

@@ -119,0 +148,0 @@ )

{
"name": "@capgo/capacitor-nfc",
"version": "8.0.28",
"version": "8.1.1",
"description": "Native NFC tag discovery, reading and writing for Capacitor apps on iOS and Android.",

@@ -50,4 +50,7 @@ "main": "dist/plugin.cjs.js",

"watch": "tsc --watch",
"prepublishOnly": "npm run build",
"check:wiring": "node scripts/check-capacitor-plugin-wiring.mjs"
"prepublishOnly": "bun run build",
"check:wiring": "node scripts/check-capacitor-plugin-wiring.mjs",
"example:install": "cd example-app && bun install --frozen-lockfile",
"example:build": "bun run build && cd example-app && bun install --frozen-lockfile && bun run build",
"example:capgo:deploy": "bun run example:build && bun scripts/deploy-example-capgo.mjs"
},

@@ -54,0 +57,0 @@ "devDependencies": {

@@ -368,8 +368,9 @@ # @capgo/capacitor-nfc

| Prop | Type | Description |
| ------------------------------ | ---------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **`invalidateAfterFirstRead`** | <code>boolean</code> | iOS-only: closes the NFC session automatically after the first successful tag read. Defaults to `true`. |
| **`alertMessage`** | <code>string</code> | iOS-only: custom message displayed in the NFC system sheet while scanning. |
| **`iosSessionType`** | <code>'tag' \| 'ndef'</code> | 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. |
| **`androidReaderModeFlags`** | <code>number</code> | Android-only: raw flags passed to `NfcAdapter.enableReaderMode`. Defaults to enabling all tag types with skipping NDEF checks. |
| Prop | Type | Description |
| ------------------------------ | ---------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **`invalidateAfterFirstRead`** | <code>boolean</code> | iOS-only: closes the NFC session automatically after the first successful tag read. Defaults to `true`. |
| **`alertMessage`** | <code>string</code> | iOS-only: custom message displayed in the NFC system sheet while scanning. |
| **`iosSessionType`** | <code>'tag' \| 'ndef'</code> | 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. |
| **`iosPollingOptions`** | <code>NfcIosPollingOption[]</code> | iOS-only: polling options to use for NFC scanning. Defaults to `['iso14443', 'iso15693', 'iso18092']` for backward compatibility. |
| **`androidReaderModeFlags`** | <code>number</code> | Android-only: raw flags passed to `NfcAdapter.enableReaderMode`. Defaults to enabling all tag types with skipping NDEF checks. |

@@ -461,2 +462,16 @@

#### NfcIosPollingOption
iOS-specific polling options for NFC scanning sessions.
These options determine the type of tags that a reader session
should detect during a polling sequence.
- 'iso14443': Polls for ISO 14443 tags
- 'iso15693': Polls for ISO 15693 tags
- 'iso18092': Polls for ISO 18092 tags
- 'pace': Polls for PACE tags (available on iOS 16 and later)
<code>'iso14443' | 'iso15693' | 'iso18092' | 'pace'</code>
#### NfcStatus

@@ -463,0 +478,0 @@