🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

@capgo/capacitor-nfc

Package Overview
Dependencies
Maintainers
1
Versions
46
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.2.0
to
8.2.1
+1
-1
dist/docs.json

@@ -275,3 +275,3 @@ {

"tags": [],
"docs": "iOS-only: polling options to use for NFC scanning.\nDefaults to `['iso14443', 'iso15693', 'iso18092']` for backward compatibility.",
"docs": "iOS-only: polling options to use for NFC scanning.\nDefaults to `['iso14443', 'iso15693']`. Apps that scan FeliCa tags can opt in\nto `'iso18092'` after configuring the required FeliCa entitlement and system codes.",
"complexTypes": [

@@ -278,0 +278,0 @@ "NfcIosPollingOption"

@@ -124,3 +124,4 @@ import type { PluginListenerHandle } from '@capacitor/core';

* iOS-only: polling options to use for NFC scanning.
* Defaults to `['iso14443', 'iso15693', 'iso18092']` for backward compatibility.
* Defaults to `['iso14443', 'iso15693']`. Apps that scan FeliCa tags can opt in
* to `'iso18092'` after configuring the required FeliCa entitlement and system codes.
*/

@@ -127,0 +128,0 @@ iosPollingOptions?: NfcIosPollingOption[];

@@ -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 * 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 and Android's NDEF discovery so that\n * detected tags remain available for writing and formatting.\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 * Event emitted when an iOS NFC reader session ends.\n *\n * This event is not emitted when a session closes normally after its first successful read.\n */\nexport interface NfcSessionEndEvent {\n reason: 'userCancelled' | 'sessionTimeout' | 'invalidated';\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 addListener(\n eventName: 'nfcSessionEnd',\n listenerFunc: (event: NfcSessionEndEvent) => 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']`. Apps that scan FeliCa tags can opt in\n * to `'iso18092'` after configuring the required FeliCa entitlement and system codes.\n */\n iosPollingOptions?: NfcIosPollingOption[];\n /**\n * Android-only: raw flags passed to `NfcAdapter.enableReaderMode`.\n * Defaults to enabling all tag types and Android's NDEF discovery so that\n * detected tags remain available for writing and formatting.\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 * Event emitted when an iOS NFC reader session ends.\n *\n * This event is not emitted when a session closes normally after its first successful read.\n */\nexport interface NfcSessionEndEvent {\n reason: 'userCancelled' | 'sessionTimeout' | 'invalidated';\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 addListener(\n eventName: 'nfcSessionEnd',\n listenerFunc: (event: NfcSessionEndEvent) => void,\n ): Promise<PluginListenerHandle>;\n}\n\nexport type { PluginListenerHandle } from '@capacitor/core';\n"]}

@@ -20,3 +20,4 @@ import Capacitor

public class NfcPlugin: CAPPlugin, CAPBridgedPlugin {
private let pluginVersion: String = "8.2.0"
private let pluginVersion: String = "8.2.1"
static let defaultIosPollingOptions = ["iso14443", "iso15693"]

@@ -138,3 +139,3 @@ public let identifier = "NfcPlugin"

let requestedPollingOptions = call.getArray("iosPollingOptions", ["iso14443", "iso15693", "iso18092"])
let requestedPollingOptions = call.getArray("iosPollingOptions", Self.defaultIosPollingOptions)
let pollingOptions = self.pollingOptions(requestedPollingOptions)

@@ -141,0 +142,0 @@ guard sessionType != "tag" || !pollingOptions.isEmpty else {

@@ -12,2 +12,7 @@ import CoreNFC

func testDefaultIosPollingOptionsExcludeFelica() {
XCTAssertEqual(NfcPlugin.defaultIosPollingOptions, ["iso14443", "iso15693"])
XCTAssertFalse(NfcPlugin.defaultIosPollingOptions.contains("iso18092"))
}
func testSessionEndReasons() {

@@ -14,0 +19,0 @@ XCTAssertEqual(reason(for: NFCReaderError.readerSessionInvalidationErrorUserCanceled.rawValue), "userCancelled")

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

@@ -5,0 +5,0 @@ "main": "dist/plugin.cjs.js",

@@ -421,3 +421,3 @@ # @capgo/capacitor-nfc

| **`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. |
| **`iosPollingOptions`** | <code>NfcIosPollingOption[]</code> | iOS-only: polling options to use for NFC scanning. Defaults to `['iso14443', 'iso15693']`. Apps that scan FeliCa tags can opt in to `'iso18092'` after configuring the required FeliCa entitlement and system codes. |
| **`androidReaderModeFlags`** | <code>number</code> | Android-only: raw flags passed to `NfcAdapter.enableReaderMode`. Defaults to enabling all tag types and Android's NDEF discovery so that detected tags remain available for writing and formatting. |

@@ -424,0 +424,0 @@