@capgo/capacitor-nfc 8.0.28 → 8.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +35 -6
- package/dist/docs.json +32 -0
- package/dist/esm/definitions.d.ts +16 -0
- package/dist/esm/definitions.js.map +1 -1
- package/ios/Sources/NfcPlugin/NfcPlugin.swift +31 -2
- package/package.json +6 -3
package/README.md
CHANGED
|
@@ -32,6 +32,20 @@ The most complete documentation will live on the Capgo docs portal. Until then,
|
|
|
32
32
|
|
|
33
33
|
## Install
|
|
34
34
|
|
|
35
|
+
You can use our AI-Assisted Setup to install the plugin. Add the Capgo skills to your AI tool using the following command:
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
npx skills add https://github.com/cap-go/capacitor-skills --skill capacitor-plugins
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Then use the following prompt:
|
|
42
|
+
|
|
43
|
+
```text
|
|
44
|
+
Use the `capacitor-plugins` skill from `cap-go/capacitor-skills` to install the `@capgo/capacitor-nfc` plugin in my project.
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
If you prefer Manual Setup, install the plugin by running the following commands and follow the platform-specific instructions below:
|
|
48
|
+
|
|
35
49
|
```bash
|
|
36
50
|
npm install @capgo/capacitor-nfc
|
|
37
51
|
npx cap sync
|
|
@@ -365,12 +379,13 @@ addListener(eventName: 'nfcStateChange', listenerFunc: (event: NfcStateChangeEve
|
|
|
365
379
|
|
|
366
380
|
Options controlling the behaviour of {@link CapacitorNfcPlugin.startScanning}.
|
|
367
381
|
|
|
368
|
-
| Prop | Type
|
|
369
|
-
| ------------------------------ |
|
|
370
|
-
| **`invalidateAfterFirstRead`** | <code>boolean</code>
|
|
371
|
-
| **`alertMessage`** | <code>string</code>
|
|
372
|
-
| **`iosSessionType`** | <code>'tag' \| 'ndef'</code>
|
|
373
|
-
| **`
|
|
382
|
+
| Prop | Type | Description |
|
|
383
|
+
| ------------------------------ | ---------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
384
|
+
| **`invalidateAfterFirstRead`** | <code>boolean</code> | iOS-only: closes the NFC session automatically after the first successful tag read. Defaults to `true`. |
|
|
385
|
+
| **`alertMessage`** | <code>string</code> | iOS-only: custom message displayed in the NFC system sheet while scanning. |
|
|
386
|
+
| **`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. |
|
|
387
|
+
| **`iosPollingOptions`** | <code>NfcIosPollingOption[]</code> | iOS-only: polling options to use for NFC scanning. Defaults to `['iso14443', 'iso15693', 'iso18092']` for backward compatibility. |
|
|
388
|
+
| **`androidReaderModeFlags`** | <code>number</code> | Android-only: raw flags passed to `NfcAdapter.enableReaderMode`. Defaults to enabling all tag types with skipping NDEF checks. |
|
|
374
389
|
|
|
375
390
|
|
|
376
391
|
#### WriteTagOptions
|
|
@@ -457,6 +472,20 @@ Event emitted whenever the NFC adapter availability changes.
|
|
|
457
472
|
### Type Aliases
|
|
458
473
|
|
|
459
474
|
|
|
475
|
+
#### NfcIosPollingOption
|
|
476
|
+
|
|
477
|
+
iOS-specific polling options for NFC scanning sessions.
|
|
478
|
+
These options determine the type of tags that a reader session
|
|
479
|
+
should detect during a polling sequence.
|
|
480
|
+
|
|
481
|
+
- 'iso14443': Polls for ISO 14443 tags
|
|
482
|
+
- 'iso15693': Polls for ISO 15693 tags
|
|
483
|
+
- 'iso18092': Polls for ISO 18092 tags
|
|
484
|
+
- 'pace': Polls for PACE tags (available on iOS 16 and later)
|
|
485
|
+
|
|
486
|
+
<code>'iso14443' | 'iso15693' | 'iso18092' | 'pace'</code>
|
|
487
|
+
|
|
488
|
+
|
|
460
489
|
#### NfcStatus
|
|
461
490
|
|
|
462
491
|
Possible NFC adapter states returned by {@link CapacitorNfcPlugin.getStatus}.
|
package/dist/docs.json
CHANGED
|
@@ -245,6 +245,15 @@
|
|
|
245
245
|
"complexTypes": [],
|
|
246
246
|
"type": "'tag' | 'ndef' | undefined"
|
|
247
247
|
},
|
|
248
|
+
{
|
|
249
|
+
"name": "iosPollingOptions",
|
|
250
|
+
"tags": [],
|
|
251
|
+
"docs": "iOS-only: polling options to use for NFC scanning.\nDefaults to `['iso14443', 'iso15693', 'iso18092']` for backward compatibility.",
|
|
252
|
+
"complexTypes": [
|
|
253
|
+
"NfcIosPollingOption"
|
|
254
|
+
],
|
|
255
|
+
"type": "NfcIosPollingOption[] | undefined"
|
|
256
|
+
},
|
|
248
257
|
{
|
|
249
258
|
"name": "androidReaderModeFlags",
|
|
250
259
|
"tags": [],
|
|
@@ -465,6 +474,29 @@
|
|
|
465
474
|
],
|
|
466
475
|
"enums": [],
|
|
467
476
|
"typeAliases": [
|
|
477
|
+
{
|
|
478
|
+
"name": "NfcIosPollingOption",
|
|
479
|
+
"slug": "nfciospollingoption",
|
|
480
|
+
"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)",
|
|
481
|
+
"types": [
|
|
482
|
+
{
|
|
483
|
+
"text": "'iso14443'",
|
|
484
|
+
"complexTypes": []
|
|
485
|
+
},
|
|
486
|
+
{
|
|
487
|
+
"text": "'iso15693'",
|
|
488
|
+
"complexTypes": []
|
|
489
|
+
},
|
|
490
|
+
{
|
|
491
|
+
"text": "'iso18092'",
|
|
492
|
+
"complexTypes": []
|
|
493
|
+
},
|
|
494
|
+
{
|
|
495
|
+
"text": "'pace'",
|
|
496
|
+
"complexTypes": []
|
|
497
|
+
}
|
|
498
|
+
]
|
|
499
|
+
},
|
|
468
500
|
{
|
|
469
501
|
"name": "NfcStatus",
|
|
470
502
|
"slug": "nfcstatus",
|
|
@@ -15,6 +15,17 @@ export type NfcStatus = 'NFC_OK' | 'NO_NFC' | 'NFC_DISABLED' | 'NDEF_PUSH_DISABL
|
|
|
15
15
|
* - `ndef-formatable`: A tag that can be formatted to NDEF.
|
|
16
16
|
*/
|
|
17
17
|
export type NfcEventType = 'tag' | 'ndef' | 'ndef-mime' | 'ndef-formatable';
|
|
18
|
+
/**
|
|
19
|
+
* iOS-specific polling options for NFC scanning sessions.
|
|
20
|
+
* These options determine the type of tags that a reader session
|
|
21
|
+
* should detect during a polling sequence.
|
|
22
|
+
*
|
|
23
|
+
* - 'iso14443': Polls for ISO 14443 tags
|
|
24
|
+
* - 'iso15693': Polls for ISO 15693 tags
|
|
25
|
+
* - 'iso18092': Polls for ISO 18092 tags
|
|
26
|
+
* - 'pace': Polls for PACE tags (available on iOS 16 and later)
|
|
27
|
+
*/
|
|
28
|
+
export type NfcIosPollingOption = 'iso14443' | 'iso15693' | 'iso18092' | 'pace';
|
|
18
29
|
/**
|
|
19
30
|
* JSON structure representing a single NDEF record.
|
|
20
31
|
*
|
|
@@ -108,6 +119,11 @@ export interface StartScanningOptions {
|
|
|
108
119
|
* Defaults to `'ndef'` for backward compatibility.
|
|
109
120
|
*/
|
|
110
121
|
iosSessionType?: 'ndef' | 'tag';
|
|
122
|
+
/**
|
|
123
|
+
* iOS-only: polling options to use for NFC scanning.
|
|
124
|
+
* Defaults to `['iso14443', 'iso15693', 'iso18092']` for backward compatibility.
|
|
125
|
+
*/
|
|
126
|
+
iosPollingOptions?: NfcIosPollingOption[];
|
|
111
127
|
/**
|
|
112
128
|
* Android-only: raw flags passed to `NfcAdapter.enableReaderMode`.
|
|
113
129
|
* Defaults to enabling all tag types with skipping NDEF checks.
|
|
@@ -1 +1 @@
|
|
|
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"]}
|
|
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 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"]}
|
|
@@ -4,7 +4,7 @@ import UIKit
|
|
|
4
4
|
|
|
5
5
|
@objc(NfcPlugin)
|
|
6
6
|
public class NfcPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
7
|
-
private let pluginVersion: String = "8.
|
|
7
|
+
private let pluginVersion: String = "8.1.2"
|
|
8
8
|
|
|
9
9
|
public let identifier = "NfcPlugin"
|
|
10
10
|
public let jsName = "CapacitorNfc"
|
|
@@ -46,6 +46,28 @@ public class NfcPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
46
46
|
NFCTagReaderSession.readingAvailable || NFCNDEFReaderSession.readingAvailable
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
+
private func pollingOptions(_ requestedPollingOptions: JSArray) -> NFCTagReaderSession.PollingOption {
|
|
50
|
+
var pollingOptions: NFCTagReaderSession.PollingOption = []
|
|
51
|
+
for option in requestedPollingOptions {
|
|
52
|
+
guard let string = option as? String else {
|
|
53
|
+
continue
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if string == "iso14443" {
|
|
57
|
+
pollingOptions.insert(.iso14443)
|
|
58
|
+
} else if string == "iso15693" {
|
|
59
|
+
pollingOptions.insert(.iso15693)
|
|
60
|
+
} else if string == "iso18092" {
|
|
61
|
+
pollingOptions.insert(.iso18092)
|
|
62
|
+
} else if string == "pace" {
|
|
63
|
+
if #available(iOS 16.0, *) {
|
|
64
|
+
pollingOptions.insert(.pace)
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return pollingOptions
|
|
69
|
+
}
|
|
70
|
+
|
|
49
71
|
private func makeTagReaderSession(
|
|
50
72
|
pollingOptions: NFCTagReaderSession.PollingOption,
|
|
51
73
|
alertMessage: String?
|
|
@@ -89,6 +111,13 @@ public class NfcPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
89
111
|
invalidateAfterFirstRead = call.getBool("invalidateAfterFirstRead", true)
|
|
90
112
|
let alertMessage = call.getString("alertMessage")
|
|
91
113
|
|
|
114
|
+
let requestedPollingOptions = call.getArray("iosPollingOptions", ["iso14443", "iso15693", "iso18092"])
|
|
115
|
+
let pollingOptions = self.pollingOptions(requestedPollingOptions)
|
|
116
|
+
guard sessionType != "tag" || !pollingOptions.isEmpty else {
|
|
117
|
+
call.reject("No valid polling options provided")
|
|
118
|
+
return
|
|
119
|
+
}
|
|
120
|
+
|
|
92
121
|
DispatchQueue.main.async {
|
|
93
122
|
// Invalidate any existing sessions
|
|
94
123
|
self.ndefReaderSession?.invalidate()
|
|
@@ -110,7 +139,7 @@ public class NfcPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
110
139
|
self.pendingAlertMessage = alertMessage
|
|
111
140
|
|
|
112
141
|
let session = self.makeTagReaderSession(
|
|
113
|
-
pollingOptions:
|
|
142
|
+
pollingOptions: pollingOptions,
|
|
114
143
|
alertMessage: alertMessage
|
|
115
144
|
)
|
|
116
145
|
self.pendingStartSession = session
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@capgo/capacitor-nfc",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.1.2",
|
|
4
4
|
"description": "Native NFC tag discovery, reading and writing for Capacitor apps on iOS and Android.",
|
|
5
5
|
"main": "dist/plugin.cjs.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -47,8 +47,11 @@
|
|
|
47
47
|
"build": "npm run clean && npm run docgen && tsc && rollup -c rollup.config.mjs",
|
|
48
48
|
"clean": "rimraf ./dist",
|
|
49
49
|
"watch": "tsc --watch",
|
|
50
|
-
"prepublishOnly": "
|
|
51
|
-
"check:wiring": "node scripts/check-capacitor-plugin-wiring.mjs"
|
|
50
|
+
"prepublishOnly": "bun run build",
|
|
51
|
+
"check:wiring": "node scripts/check-capacitor-plugin-wiring.mjs",
|
|
52
|
+
"example:install": "cd example-app && bun install --frozen-lockfile",
|
|
53
|
+
"example:build": "bun run build && cd example-app && bun install --frozen-lockfile && bun run build",
|
|
54
|
+
"example:capgo:deploy": "bun run example:build && bun scripts/deploy-example-capgo.mjs"
|
|
52
55
|
},
|
|
53
56
|
"devDependencies": {
|
|
54
57
|
"@capacitor/android": "^8.0.0",
|