@capgo/capacitor-nfc 8.0.10 → 8.0.12

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 CHANGED
@@ -44,6 +44,29 @@ Remember to add the required platform configuration:
44
44
 
45
45
  ## Usage
46
46
 
47
+ ### Checking NFC hardware support
48
+
49
+ Before attempting to use NFC features, you can check if the device has NFC hardware:
50
+
51
+ ```ts
52
+ import { CapacitorNfc } from '@capgo/capacitor-nfc';
53
+
54
+ const { supported } = await CapacitorNfc.isSupported();
55
+ if (!supported) {
56
+ console.warn('This device does not have NFC hardware');
57
+ // Hide NFC features in your UI
58
+ } else {
59
+ // Check if NFC is currently enabled
60
+ const { status } = await CapacitorNfc.getStatus();
61
+ if (status === 'NFC_DISABLED') {
62
+ console.warn('NFC is disabled. Prompt user to enable it.');
63
+ // Optionally show settings button
64
+ }
65
+ }
66
+ ```
67
+
68
+ ### Reading NDEF tags (default behavior)
69
+
47
70
  ```ts
48
71
  import { CapacitorNfc } from '@capgo/capacitor-nfc';
49
72
 
@@ -79,6 +102,36 @@ await listener.remove();
79
102
  await CapacitorNfc.stopScanning();
80
103
  ```
81
104
 
105
+ ### Reading raw tags (iOS) - Get UID from unformatted tags
106
+
107
+ ```ts
108
+ import { CapacitorNfc } from '@capgo/capacitor-nfc';
109
+
110
+ // Use 'tag' session type to read raw (non-NDEF) tags
111
+ await CapacitorNfc.startScanning({
112
+ iosSessionType: 'tag', // Enable raw tag reading on iOS
113
+ alertMessage: 'Hold your card near the device',
114
+ });
115
+
116
+ const listener = await CapacitorNfc.addListener('nfcEvent', (event) => {
117
+ console.info('Tag detected:', event.type); // 'tag' or 'ndef'
118
+
119
+ // Read the UID (identifier) - works for both NDEF and raw tags
120
+ if (event.tag?.id) {
121
+ const uid = event.tag.id.map(byte => byte.toString(16).padStart(2, '0').toUpperCase()).join(':');
122
+ console.info('Tag UID:', uid); // e.g., "04:A1:B2:C3:D4:E5:F6"
123
+ }
124
+
125
+ // If the tag has NDEF data, it will also be available
126
+ if (event.tag?.ndefMessage) {
127
+ console.info('NDEF records:', event.tag.ndefMessage);
128
+ }
129
+ });
130
+
131
+ await listener.remove();
132
+ await CapacitorNfc.stopScanning();
133
+ ```
134
+
82
135
  ## API
83
136
 
84
137
  <docgen-index>
@@ -93,6 +146,7 @@ await CapacitorNfc.stopScanning();
93
146
  * [`getStatus()`](#getstatus)
94
147
  * [`showSettings()`](#showsettings)
95
148
  * [`getPluginVersion()`](#getpluginversion)
149
+ * [`isSupported()`](#issupported)
96
150
  * [`addListener('nfcEvent', ...)`](#addlistenernfcevent-)
97
151
  * [`addListener('tagDiscovered' | 'ndefDiscovered' | 'ndefMimeDiscovered' | 'ndefFormatableDiscovered', ...)`](#addlistenertagdiscovered--ndefdiscovered--ndefmimediscovered--ndefformatablediscovered-)
98
152
  * [`addListener('nfcStateChange', ...)`](#addlistenernfcstatechange-)
@@ -235,6 +289,26 @@ Returns the version string baked into the native plugin.
235
289
  --------------------
236
290
 
237
291
 
292
+ ### isSupported()
293
+
294
+ ```typescript
295
+ isSupported() => Promise<{ supported: boolean; }>
296
+ ```
297
+
298
+ Checks whether the device has NFC hardware support.
299
+
300
+ Returns `true` if NFC hardware is present on the device, regardless of
301
+ whether NFC is currently enabled or disabled. Returns `false` if the
302
+ device does not have NFC hardware.
303
+
304
+ Use this method to determine if NFC features should be shown in your
305
+ app's UI. To check if NFC is currently enabled, use `getStatus()`.
306
+
307
+ **Returns:** <code>Promise&lt;{ supported: boolean; }&gt;</code>
308
+
309
+ --------------------
310
+
311
+
238
312
  ### addListener('nfcEvent', ...)
239
313
 
240
314
  ```typescript
@@ -290,11 +364,12 @@ addListener(eventName: 'nfcStateChange', listenerFunc: (event: NfcStateChangeEve
290
364
 
291
365
  Options controlling the behaviour of {@link CapacitorNfcPlugin.startScanning}.
292
366
 
293
- | Prop | Type | Description |
294
- | ------------------------------ | -------------------- | ------------------------------------------------------------------------------------------------------------------------------ |
295
- | **`invalidateAfterFirstRead`** | <code>boolean</code> | iOS-only: closes the NFC session automatically after the first successful tag read. Defaults to `true`. |
296
- | **`alertMessage`** | <code>string</code> | iOS-only: custom message displayed in the NFC system sheet while scanning. |
297
- | **`androidReaderModeFlags`** | <code>number</code> | Android-only: raw flags passed to `NfcAdapter.enableReaderMode`. Defaults to enabling all tag types with skipping NDEF checks. |
367
+ | Prop | Type | Description |
368
+ | ------------------------------ | ---------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
369
+ | **`invalidateAfterFirstRead`** | <code>boolean</code> | iOS-only: closes the NFC session automatically after the first successful tag read. Defaults to `true`. |
370
+ | **`alertMessage`** | <code>string</code> | iOS-only: custom message displayed in the NFC system sheet while scanning. |
371
+ | **`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. Defaults to `'ndef'` for backward compatibility. |
372
+ | **`androidReaderModeFlags`** | <code>number</code> | Android-only: raw flags passed to `NfcAdapter.enableReaderMode`. Defaults to enabling all tag types with skipping NDEF checks. |
298
373
 
299
374
 
300
375
  #### WriteTagOptions
@@ -280,6 +280,13 @@ public class CapacitorNfcPlugin extends Plugin {
280
280
  call.resolve(result);
281
281
  }
282
282
 
283
+ @PluginMethod
284
+ public void isSupported(PluginCall call) {
285
+ JSObject result = new JSObject();
286
+ result.put("supported", adapter != null);
287
+ call.resolve(result);
288
+ }
289
+
283
290
  private void performWrite(PluginCall call, Tag tag, NdefMessage message, boolean allowFormat) {
284
291
  executor.execute(() -> {
285
292
  Ndef ndef = Ndef.get(tag);
package/dist/docs.json CHANGED
@@ -131,6 +131,16 @@
131
131
  "complexTypes": [],
132
132
  "slug": "getpluginversion"
133
133
  },
134
+ {
135
+ "name": "isSupported",
136
+ "signature": "() => Promise<{ supported: boolean; }>",
137
+ "parameters": [],
138
+ "returns": "Promise<{ supported: boolean; }>",
139
+ "tags": [],
140
+ "docs": "Checks whether the device has NFC hardware support.\n\nReturns `true` if NFC hardware is present on the device, regardless of\nwhether NFC is currently enabled or disabled. Returns `false` if the\ndevice does not have NFC hardware.\n\nUse this method to determine if NFC features should be shown in your\napp's UI. To check if NFC is currently enabled, use `getStatus()`.",
141
+ "complexTypes": [],
142
+ "slug": "issupported"
143
+ },
134
144
  {
135
145
  "name": "addListener",
136
146
  "signature": "(eventName: 'nfcEvent', listenerFunc: (event: NfcEvent) => void) => Promise<PluginListenerHandle>",
@@ -228,6 +238,13 @@
228
238
  "complexTypes": [],
229
239
  "type": "string | undefined"
230
240
  },
241
+ {
242
+ "name": "iosSessionType",
243
+ "tags": [],
244
+ "docs": "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.\nDefaults to `'ndef'` for backward compatibility.",
245
+ "complexTypes": [],
246
+ "type": "'tag' | 'ndef' | undefined"
247
+ },
231
248
  {
232
249
  "name": "androidReaderModeFlags",
233
250
  "tags": [],
@@ -97,6 +97,14 @@ export interface StartScanningOptions {
97
97
  * iOS-only: custom message displayed in the NFC system sheet while scanning.
98
98
  */
99
99
  alertMessage?: string;
100
+ /**
101
+ * iOS-only: session type to use for NFC scanning.
102
+ * - `'ndef'`: Uses NFCNDEFReaderSession (default). Only detects NDEF-formatted tags.
103
+ * - `'tag'`: Uses NFCTagReaderSession. Detects both NDEF and non-NDEF tags (e.g., raw MIFARE tags).
104
+ * Allows reading UID from unformatted tags.
105
+ * Defaults to `'ndef'` for backward compatibility.
106
+ */
107
+ iosSessionType?: 'ndef' | 'tag';
100
108
  /**
101
109
  * Android-only: raw flags passed to `NfcAdapter.enableReaderMode`.
102
110
  * Defaults to enabling all tag types with skipping NDEF checks.
@@ -181,6 +189,19 @@ export interface CapacitorNfcPlugin {
181
189
  getPluginVersion(): Promise<{
182
190
  version: string;
183
191
  }>;
192
+ /**
193
+ * Checks whether the device has NFC hardware support.
194
+ *
195
+ * Returns `true` if NFC hardware is present on the device, regardless of
196
+ * whether NFC is currently enabled or disabled. Returns `false` if the
197
+ * device does not have NFC hardware.
198
+ *
199
+ * Use this method to determine if NFC features should be shown in your
200
+ * app's UI. To check if NFC is currently enabled, use `getStatus()`.
201
+ */
202
+ isSupported(): Promise<{
203
+ supported: boolean;
204
+ }>;
184
205
  addListener(eventName: 'nfcEvent', listenerFunc: (event: NfcEvent) => void): Promise<PluginListenerHandle>;
185
206
  addListener(eventName: 'tagDiscovered' | 'ndefDiscovered' | 'ndefMimeDiscovered' | 'ndefFormatableDiscovered', listenerFunc: (event: NfcEvent) => void): Promise<PluginListenerHandle>;
186
207
  addListener(eventName: 'nfcStateChange', listenerFunc: (event: NfcStateChangeEvent) => void): Promise<PluginListenerHandle>;
@@ -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 * 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 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 * 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 * 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"]}
package/dist/esm/web.d.ts CHANGED
@@ -16,6 +16,9 @@ export declare class CapacitorNfcWeb extends WebPlugin implements CapacitorNfcPl
16
16
  getPluginVersion(): Promise<{
17
17
  version: string;
18
18
  }>;
19
+ isSupported(): Promise<{
20
+ supported: boolean;
21
+ }>;
19
22
  addListener(eventName: 'nfcEvent', listenerFunc: (event: NfcEvent) => void): Promise<PluginListenerHandle>;
20
23
  addListener(eventName: 'tagDiscovered' | 'ndefDiscovered' | 'ndefMimeDiscovered' | 'ndefFormatableDiscovered', listenerFunc: (event: NfcEvent) => void): Promise<PluginListenerHandle>;
21
24
  addListener(eventName: 'nfcStateChange', listenerFunc: (event: NfcStateChangeEvent) => void): Promise<PluginListenerHandle>;
package/dist/esm/web.js CHANGED
@@ -33,6 +33,9 @@ export class CapacitorNfcWeb extends WebPlugin {
33
33
  async getPluginVersion() {
34
34
  return { version: '0.0.0-web' };
35
35
  }
36
+ async isSupported() {
37
+ return { supported: false };
38
+ }
36
39
  async addListener(eventName, _listenerFunc) {
37
40
  this.unsupported(`addListener(${eventName})`);
38
41
  }
@@ -1 +1 @@
1
- {"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAY5C,MAAM,OAAO,eAAgB,SAAQ,SAAS;IACpC,WAAW,CAAC,MAAc;QAChC,MAAM,IAAI,CAAC,aAAa,CAAC,gBAAgB,MAAM,6CAA6C,CAAC,CAAC;IAChG,CAAC;IAED,KAAK,CAAC,aAAa,CAAC,QAA+B;QACjD,IAAI,CAAC,WAAW,CAAC,eAAe,CAAC,CAAC;IACpC,CAAC;IAED,KAAK,CAAC,YAAY;QAChB,IAAI,CAAC,WAAW,CAAC,cAAc,CAAC,CAAC;IACnC,CAAC;IAED,KAAK,CAAC,KAAK,CAAC,QAAyB;QACnC,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;IAC5B,CAAC;IAED,KAAK,CAAC,KAAK;QACT,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;IAC5B,CAAC;IAED,KAAK,CAAC,YAAY;QAChB,IAAI,CAAC,WAAW,CAAC,cAAc,CAAC,CAAC;IACnC,CAAC;IAED,KAAK,CAAC,KAAK,CAAC,QAAyB;QACnC,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;IAC5B,CAAC;IAED,KAAK,CAAC,OAAO;QACX,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC;IAC9B,CAAC;IAED,KAAK,CAAC,SAAS;QACb,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC;IAC9B,CAAC;IAED,KAAK,CAAC,YAAY;QAChB,IAAI,CAAC,WAAW,CAAC,cAAc,CAAC,CAAC;IACnC,CAAC;IAED,KAAK,CAAC,gBAAgB;QACpB,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,CAAC;IAClC,CAAC;IAWD,KAAK,CAAC,WAAW,CAAC,SAAiB,EAAE,aAAuC;QAC1E,IAAI,CAAC,WAAW,CAAC,eAAe,SAAS,GAAG,CAAC,CAAC;IAChD,CAAC;CACF","sourcesContent":["import { WebPlugin } from '@capacitor/core';\n\nimport type {\n CapacitorNfcPlugin,\n NfcStateChangeEvent,\n NfcEvent,\n ShareTagOptions,\n StartScanningOptions,\n WriteTagOptions,\n PluginListenerHandle,\n} from './definitions';\n\nexport class CapacitorNfcWeb extends WebPlugin implements CapacitorNfcPlugin {\n private unsupported(method: string): never {\n throw this.unimplemented(`CapacitorNfc.${method} is not available in a browser environment.`);\n }\n\n async startScanning(_options?: StartScanningOptions): Promise<void> {\n this.unsupported('startScanning');\n }\n\n async stopScanning(): Promise<void> {\n this.unsupported('stopScanning');\n }\n\n async write(_options: WriteTagOptions): Promise<void> {\n this.unsupported('write');\n }\n\n async erase(): Promise<void> {\n this.unsupported('erase');\n }\n\n async makeReadOnly(): Promise<void> {\n this.unsupported('makeReadOnly');\n }\n\n async share(_options: ShareTagOptions): Promise<void> {\n this.unsupported('share');\n }\n\n async unshare(): Promise<void> {\n this.unsupported('unshare');\n }\n\n async getStatus(): Promise<{ status: 'NO_NFC' }> {\n return { status: 'NO_NFC' };\n }\n\n async showSettings(): Promise<void> {\n this.unsupported('showSettings');\n }\n\n async getPluginVersion(): Promise<{ version: string }> {\n return { version: '0.0.0-web' };\n }\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 async addListener(eventName: string, _listenerFunc: (..._args: any[]) => any): Promise<PluginListenerHandle> {\n this.unsupported(`addListener(${eventName})`);\n }\n}\n"]}
1
+ {"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAY5C,MAAM,OAAO,eAAgB,SAAQ,SAAS;IACpC,WAAW,CAAC,MAAc;QAChC,MAAM,IAAI,CAAC,aAAa,CAAC,gBAAgB,MAAM,6CAA6C,CAAC,CAAC;IAChG,CAAC;IAED,KAAK,CAAC,aAAa,CAAC,QAA+B;QACjD,IAAI,CAAC,WAAW,CAAC,eAAe,CAAC,CAAC;IACpC,CAAC;IAED,KAAK,CAAC,YAAY;QAChB,IAAI,CAAC,WAAW,CAAC,cAAc,CAAC,CAAC;IACnC,CAAC;IAED,KAAK,CAAC,KAAK,CAAC,QAAyB;QACnC,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;IAC5B,CAAC;IAED,KAAK,CAAC,KAAK;QACT,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;IAC5B,CAAC;IAED,KAAK,CAAC,YAAY;QAChB,IAAI,CAAC,WAAW,CAAC,cAAc,CAAC,CAAC;IACnC,CAAC;IAED,KAAK,CAAC,KAAK,CAAC,QAAyB;QACnC,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;IAC5B,CAAC;IAED,KAAK,CAAC,OAAO;QACX,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC;IAC9B,CAAC;IAED,KAAK,CAAC,SAAS;QACb,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC;IAC9B,CAAC;IAED,KAAK,CAAC,YAAY;QAChB,IAAI,CAAC,WAAW,CAAC,cAAc,CAAC,CAAC;IACnC,CAAC;IAED,KAAK,CAAC,gBAAgB;QACpB,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,CAAC;IAClC,CAAC;IAED,KAAK,CAAC,WAAW;QACf,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;IAC9B,CAAC;IAWD,KAAK,CAAC,WAAW,CAAC,SAAiB,EAAE,aAAuC;QAC1E,IAAI,CAAC,WAAW,CAAC,eAAe,SAAS,GAAG,CAAC,CAAC;IAChD,CAAC;CACF","sourcesContent":["import { WebPlugin } from '@capacitor/core';\n\nimport type {\n CapacitorNfcPlugin,\n NfcStateChangeEvent,\n NfcEvent,\n ShareTagOptions,\n StartScanningOptions,\n WriteTagOptions,\n PluginListenerHandle,\n} from './definitions';\n\nexport class CapacitorNfcWeb extends WebPlugin implements CapacitorNfcPlugin {\n private unsupported(method: string): never {\n throw this.unimplemented(`CapacitorNfc.${method} is not available in a browser environment.`);\n }\n\n async startScanning(_options?: StartScanningOptions): Promise<void> {\n this.unsupported('startScanning');\n }\n\n async stopScanning(): Promise<void> {\n this.unsupported('stopScanning');\n }\n\n async write(_options: WriteTagOptions): Promise<void> {\n this.unsupported('write');\n }\n\n async erase(): Promise<void> {\n this.unsupported('erase');\n }\n\n async makeReadOnly(): Promise<void> {\n this.unsupported('makeReadOnly');\n }\n\n async share(_options: ShareTagOptions): Promise<void> {\n this.unsupported('share');\n }\n\n async unshare(): Promise<void> {\n this.unsupported('unshare');\n }\n\n async getStatus(): Promise<{ status: 'NO_NFC' }> {\n return { status: 'NO_NFC' };\n }\n\n async showSettings(): Promise<void> {\n this.unsupported('showSettings');\n }\n\n async getPluginVersion(): Promise<{ version: string }> {\n return { version: '0.0.0-web' };\n }\n\n async isSupported(): Promise<{ supported: boolean }> {\n return { supported: false };\n }\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 async addListener(eventName: string, _listenerFunc: (..._args: any[]) => any): Promise<PluginListenerHandle> {\n this.unsupported(`addListener(${eventName})`);\n }\n}\n"]}
@@ -40,6 +40,9 @@ class CapacitorNfcWeb extends core.WebPlugin {
40
40
  async getPluginVersion() {
41
41
  return { version: '0.0.0-web' };
42
42
  }
43
+ async isSupported() {
44
+ return { supported: false };
45
+ }
43
46
  async addListener(eventName, _listenerFunc) {
44
47
  this.unsupported(`addListener(${eventName})`);
45
48
  }
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.cjs.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst CapacitorNfc = registerPlugin('CapacitorNfc', {\n web: () => import('./web').then((m) => new m.CapacitorNfcWeb()),\n});\nexport * from './definitions';\nexport { CapacitorNfc };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class CapacitorNfcWeb extends WebPlugin {\n unsupported(method) {\n throw this.unimplemented(`CapacitorNfc.${method} is not available in a browser environment.`);\n }\n async startScanning(_options) {\n this.unsupported('startScanning');\n }\n async stopScanning() {\n this.unsupported('stopScanning');\n }\n async write(_options) {\n this.unsupported('write');\n }\n async erase() {\n this.unsupported('erase');\n }\n async makeReadOnly() {\n this.unsupported('makeReadOnly');\n }\n async share(_options) {\n this.unsupported('share');\n }\n async unshare() {\n this.unsupported('unshare');\n }\n async getStatus() {\n return { status: 'NO_NFC' };\n }\n async showSettings() {\n this.unsupported('showSettings');\n }\n async getPluginVersion() {\n return { version: '0.0.0-web' };\n }\n async addListener(eventName, _listenerFunc) {\n this.unsupported(`addListener(${eventName})`);\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;;AACK,MAAC,YAAY,GAAGA,mBAAc,CAAC,cAAc,EAAE;AACpD,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,eAAe,EAAE,CAAC;AACnE,CAAC;;ACFM,MAAM,eAAe,SAASC,cAAS,CAAC;AAC/C,IAAI,WAAW,CAAC,MAAM,EAAE;AACxB,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,CAAC,aAAa,EAAE,MAAM,CAAC,2CAA2C,CAAC,CAAC;AACrG,IAAI;AACJ,IAAI,MAAM,aAAa,CAAC,QAAQ,EAAE;AAClC,QAAQ,IAAI,CAAC,WAAW,CAAC,eAAe,CAAC;AACzC,IAAI;AACJ,IAAI,MAAM,YAAY,GAAG;AACzB,QAAQ,IAAI,CAAC,WAAW,CAAC,cAAc,CAAC;AACxC,IAAI;AACJ,IAAI,MAAM,KAAK,CAAC,QAAQ,EAAE;AAC1B,QAAQ,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC;AACjC,IAAI;AACJ,IAAI,MAAM,KAAK,GAAG;AAClB,QAAQ,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC;AACjC,IAAI;AACJ,IAAI,MAAM,YAAY,GAAG;AACzB,QAAQ,IAAI,CAAC,WAAW,CAAC,cAAc,CAAC;AACxC,IAAI;AACJ,IAAI,MAAM,KAAK,CAAC,QAAQ,EAAE;AAC1B,QAAQ,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC;AACjC,IAAI;AACJ,IAAI,MAAM,OAAO,GAAG;AACpB,QAAQ,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC;AACnC,IAAI;AACJ,IAAI,MAAM,SAAS,GAAG;AACtB,QAAQ,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE;AACnC,IAAI;AACJ,IAAI,MAAM,YAAY,GAAG;AACzB,QAAQ,IAAI,CAAC,WAAW,CAAC,cAAc,CAAC;AACxC,IAAI;AACJ,IAAI,MAAM,gBAAgB,GAAG;AAC7B,QAAQ,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE;AACvC,IAAI;AACJ,IAAI,MAAM,WAAW,CAAC,SAAS,EAAE,aAAa,EAAE;AAChD,QAAQ,IAAI,CAAC,WAAW,CAAC,CAAC,YAAY,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC;AACrD,IAAI;AACJ;;;;;;;;;"}
1
+ {"version":3,"file":"plugin.cjs.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst CapacitorNfc = registerPlugin('CapacitorNfc', {\n web: () => import('./web').then((m) => new m.CapacitorNfcWeb()),\n});\nexport * from './definitions';\nexport { CapacitorNfc };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class CapacitorNfcWeb extends WebPlugin {\n unsupported(method) {\n throw this.unimplemented(`CapacitorNfc.${method} is not available in a browser environment.`);\n }\n async startScanning(_options) {\n this.unsupported('startScanning');\n }\n async stopScanning() {\n this.unsupported('stopScanning');\n }\n async write(_options) {\n this.unsupported('write');\n }\n async erase() {\n this.unsupported('erase');\n }\n async makeReadOnly() {\n this.unsupported('makeReadOnly');\n }\n async share(_options) {\n this.unsupported('share');\n }\n async unshare() {\n this.unsupported('unshare');\n }\n async getStatus() {\n return { status: 'NO_NFC' };\n }\n async showSettings() {\n this.unsupported('showSettings');\n }\n async getPluginVersion() {\n return { version: '0.0.0-web' };\n }\n async isSupported() {\n return { supported: false };\n }\n async addListener(eventName, _listenerFunc) {\n this.unsupported(`addListener(${eventName})`);\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;;AACK,MAAC,YAAY,GAAGA,mBAAc,CAAC,cAAc,EAAE;AACpD,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,eAAe,EAAE,CAAC;AACnE,CAAC;;ACFM,MAAM,eAAe,SAASC,cAAS,CAAC;AAC/C,IAAI,WAAW,CAAC,MAAM,EAAE;AACxB,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,CAAC,aAAa,EAAE,MAAM,CAAC,2CAA2C,CAAC,CAAC;AACrG,IAAI;AACJ,IAAI,MAAM,aAAa,CAAC,QAAQ,EAAE;AAClC,QAAQ,IAAI,CAAC,WAAW,CAAC,eAAe,CAAC;AACzC,IAAI;AACJ,IAAI,MAAM,YAAY,GAAG;AACzB,QAAQ,IAAI,CAAC,WAAW,CAAC,cAAc,CAAC;AACxC,IAAI;AACJ,IAAI,MAAM,KAAK,CAAC,QAAQ,EAAE;AAC1B,QAAQ,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC;AACjC,IAAI;AACJ,IAAI,MAAM,KAAK,GAAG;AAClB,QAAQ,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC;AACjC,IAAI;AACJ,IAAI,MAAM,YAAY,GAAG;AACzB,QAAQ,IAAI,CAAC,WAAW,CAAC,cAAc,CAAC;AACxC,IAAI;AACJ,IAAI,MAAM,KAAK,CAAC,QAAQ,EAAE;AAC1B,QAAQ,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC;AACjC,IAAI;AACJ,IAAI,MAAM,OAAO,GAAG;AACpB,QAAQ,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC;AACnC,IAAI;AACJ,IAAI,MAAM,SAAS,GAAG;AACtB,QAAQ,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE;AACnC,IAAI;AACJ,IAAI,MAAM,YAAY,GAAG;AACzB,QAAQ,IAAI,CAAC,WAAW,CAAC,cAAc,CAAC;AACxC,IAAI;AACJ,IAAI,MAAM,gBAAgB,GAAG;AAC7B,QAAQ,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE;AACvC,IAAI;AACJ,IAAI,MAAM,WAAW,GAAG;AACxB,QAAQ,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE;AACnC,IAAI;AACJ,IAAI,MAAM,WAAW,CAAC,SAAS,EAAE,aAAa,EAAE;AAChD,QAAQ,IAAI,CAAC,WAAW,CAAC,CAAC,YAAY,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC;AACrD,IAAI;AACJ;;;;;;;;;"}
package/dist/plugin.js CHANGED
@@ -39,6 +39,9 @@ var capacitorCapacitorNfc = (function (exports, core) {
39
39
  async getPluginVersion() {
40
40
  return { version: '0.0.0-web' };
41
41
  }
42
+ async isSupported() {
43
+ return { supported: false };
44
+ }
42
45
  async addListener(eventName, _listenerFunc) {
43
46
  this.unsupported(`addListener(${eventName})`);
44
47
  }
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst CapacitorNfc = registerPlugin('CapacitorNfc', {\n web: () => import('./web').then((m) => new m.CapacitorNfcWeb()),\n});\nexport * from './definitions';\nexport { CapacitorNfc };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class CapacitorNfcWeb extends WebPlugin {\n unsupported(method) {\n throw this.unimplemented(`CapacitorNfc.${method} is not available in a browser environment.`);\n }\n async startScanning(_options) {\n this.unsupported('startScanning');\n }\n async stopScanning() {\n this.unsupported('stopScanning');\n }\n async write(_options) {\n this.unsupported('write');\n }\n async erase() {\n this.unsupported('erase');\n }\n async makeReadOnly() {\n this.unsupported('makeReadOnly');\n }\n async share(_options) {\n this.unsupported('share');\n }\n async unshare() {\n this.unsupported('unshare');\n }\n async getStatus() {\n return { status: 'NO_NFC' };\n }\n async showSettings() {\n this.unsupported('showSettings');\n }\n async getPluginVersion() {\n return { version: '0.0.0-web' };\n }\n async addListener(eventName, _listenerFunc) {\n this.unsupported(`addListener(${eventName})`);\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;AACK,UAAC,YAAY,GAAGA,mBAAc,CAAC,cAAc,EAAE;IACpD,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,eAAe,EAAE,CAAC;IACnE,CAAC;;ICFM,MAAM,eAAe,SAASC,cAAS,CAAC;IAC/C,IAAI,WAAW,CAAC,MAAM,EAAE;IACxB,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,CAAC,aAAa,EAAE,MAAM,CAAC,2CAA2C,CAAC,CAAC;IACrG,IAAI;IACJ,IAAI,MAAM,aAAa,CAAC,QAAQ,EAAE;IAClC,QAAQ,IAAI,CAAC,WAAW,CAAC,eAAe,CAAC;IACzC,IAAI;IACJ,IAAI,MAAM,YAAY,GAAG;IACzB,QAAQ,IAAI,CAAC,WAAW,CAAC,cAAc,CAAC;IACxC,IAAI;IACJ,IAAI,MAAM,KAAK,CAAC,QAAQ,EAAE;IAC1B,QAAQ,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC;IACjC,IAAI;IACJ,IAAI,MAAM,KAAK,GAAG;IAClB,QAAQ,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC;IACjC,IAAI;IACJ,IAAI,MAAM,YAAY,GAAG;IACzB,QAAQ,IAAI,CAAC,WAAW,CAAC,cAAc,CAAC;IACxC,IAAI;IACJ,IAAI,MAAM,KAAK,CAAC,QAAQ,EAAE;IAC1B,QAAQ,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC;IACjC,IAAI;IACJ,IAAI,MAAM,OAAO,GAAG;IACpB,QAAQ,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC;IACnC,IAAI;IACJ,IAAI,MAAM,SAAS,GAAG;IACtB,QAAQ,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE;IACnC,IAAI;IACJ,IAAI,MAAM,YAAY,GAAG;IACzB,QAAQ,IAAI,CAAC,WAAW,CAAC,cAAc,CAAC;IACxC,IAAI;IACJ,IAAI,MAAM,gBAAgB,GAAG;IAC7B,QAAQ,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE;IACvC,IAAI;IACJ,IAAI,MAAM,WAAW,CAAC,SAAS,EAAE,aAAa,EAAE;IAChD,QAAQ,IAAI,CAAC,WAAW,CAAC,CAAC,YAAY,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC;IACrD,IAAI;IACJ;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"plugin.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst CapacitorNfc = registerPlugin('CapacitorNfc', {\n web: () => import('./web').then((m) => new m.CapacitorNfcWeb()),\n});\nexport * from './definitions';\nexport { CapacitorNfc };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class CapacitorNfcWeb extends WebPlugin {\n unsupported(method) {\n throw this.unimplemented(`CapacitorNfc.${method} is not available in a browser environment.`);\n }\n async startScanning(_options) {\n this.unsupported('startScanning');\n }\n async stopScanning() {\n this.unsupported('stopScanning');\n }\n async write(_options) {\n this.unsupported('write');\n }\n async erase() {\n this.unsupported('erase');\n }\n async makeReadOnly() {\n this.unsupported('makeReadOnly');\n }\n async share(_options) {\n this.unsupported('share');\n }\n async unshare() {\n this.unsupported('unshare');\n }\n async getStatus() {\n return { status: 'NO_NFC' };\n }\n async showSettings() {\n this.unsupported('showSettings');\n }\n async getPluginVersion() {\n return { version: '0.0.0-web' };\n }\n async isSupported() {\n return { supported: false };\n }\n async addListener(eventName, _listenerFunc) {\n this.unsupported(`addListener(${eventName})`);\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;AACK,UAAC,YAAY,GAAGA,mBAAc,CAAC,cAAc,EAAE;IACpD,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,eAAe,EAAE,CAAC;IACnE,CAAC;;ICFM,MAAM,eAAe,SAASC,cAAS,CAAC;IAC/C,IAAI,WAAW,CAAC,MAAM,EAAE;IACxB,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,CAAC,aAAa,EAAE,MAAM,CAAC,2CAA2C,CAAC,CAAC;IACrG,IAAI;IACJ,IAAI,MAAM,aAAa,CAAC,QAAQ,EAAE;IAClC,QAAQ,IAAI,CAAC,WAAW,CAAC,eAAe,CAAC;IACzC,IAAI;IACJ,IAAI,MAAM,YAAY,GAAG;IACzB,QAAQ,IAAI,CAAC,WAAW,CAAC,cAAc,CAAC;IACxC,IAAI;IACJ,IAAI,MAAM,KAAK,CAAC,QAAQ,EAAE;IAC1B,QAAQ,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC;IACjC,IAAI;IACJ,IAAI,MAAM,KAAK,GAAG;IAClB,QAAQ,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC;IACjC,IAAI;IACJ,IAAI,MAAM,YAAY,GAAG;IACzB,QAAQ,IAAI,CAAC,WAAW,CAAC,cAAc,CAAC;IACxC,IAAI;IACJ,IAAI,MAAM,KAAK,CAAC,QAAQ,EAAE;IAC1B,QAAQ,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC;IACjC,IAAI;IACJ,IAAI,MAAM,OAAO,GAAG;IACpB,QAAQ,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC;IACnC,IAAI;IACJ,IAAI,MAAM,SAAS,GAAG;IACtB,QAAQ,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE;IACnC,IAAI;IACJ,IAAI,MAAM,YAAY,GAAG;IACzB,QAAQ,IAAI,CAAC,WAAW,CAAC,cAAc,CAAC;IACxC,IAAI;IACJ,IAAI,MAAM,gBAAgB,GAAG;IAC7B,QAAQ,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE;IACvC,IAAI;IACJ,IAAI,MAAM,WAAW,GAAG;IACxB,QAAQ,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE;IACnC,IAAI;IACJ,IAAI,MAAM,WAAW,CAAC,SAAS,EAAE,aAAa,EAAE;IAChD,QAAQ,IAAI,CAAC,WAAW,CAAC,CAAC,YAAY,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC;IACrD,IAAI;IACJ;;;;;;;;;;;;;;;"}
@@ -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.0.10"
7
+ private let pluginVersion: String = "8.0.12"
8
8
 
9
9
  public let identifier = "NfcPlugin"
10
10
  public let jsName = "CapacitorNfc"
@@ -18,13 +18,16 @@ public class NfcPlugin: CAPPlugin, CAPBridgedPlugin {
18
18
  CAPPluginMethod(name: "unshare", returnType: CAPPluginReturnPromise),
19
19
  CAPPluginMethod(name: "getStatus", returnType: CAPPluginReturnPromise),
20
20
  CAPPluginMethod(name: "showSettings", returnType: CAPPluginReturnPromise),
21
- CAPPluginMethod(name: "getPluginVersion", returnType: CAPPluginReturnPromise)
21
+ CAPPluginMethod(name: "getPluginVersion", returnType: CAPPluginReturnPromise),
22
+ CAPPluginMethod(name: "isSupported", returnType: CAPPluginReturnPromise)
22
23
  ]
23
24
 
24
- private var readerSession: NFCNDEFReaderSession?
25
+ private var ndefReaderSession: NFCNDEFReaderSession?
26
+ private var tagReaderSession: NFCTagReaderSession?
25
27
  private let sessionQueue = DispatchQueue(label: "app.capgo.nfc.session")
26
28
  private var currentTag: NFCNDEFTag?
27
29
  private var invalidateAfterFirstRead = true
30
+ private var sessionType: String = "ndef"
28
31
 
29
32
  @objc public func startScanning(_ call: CAPPluginCall) {
30
33
  #if targetEnvironment(simulator)
@@ -38,14 +41,38 @@ public class NfcPlugin: CAPPlugin, CAPBridgedPlugin {
38
41
 
39
42
  invalidateAfterFirstRead = call.getBool("invalidateAfterFirstRead", true)
40
43
  let alertMessage = call.getString("alertMessage")
44
+ sessionType = call.getString("iosSessionType", "ndef")
41
45
 
42
46
  DispatchQueue.main.async {
43
- self.readerSession?.invalidate()
44
- self.readerSession = NFCNDEFReaderSession(delegate: self, queue: self.sessionQueue, invalidateAfterFirstRead: self.invalidateAfterFirstRead)
45
- if let alertMessage, !alertMessage.isEmpty {
46
- self.readerSession?.alertMessage = alertMessage
47
+ // Invalidate any existing sessions
48
+ self.ndefReaderSession?.invalidate()
49
+ self.ndefReaderSession = nil
50
+ self.tagReaderSession?.invalidate()
51
+ self.tagReaderSession = nil
52
+
53
+ if self.sessionType == "tag" {
54
+ // Use NFCTagReaderSession for raw tag support
55
+ self.tagReaderSession = NFCTagReaderSession(
56
+ pollingOption: [.iso14443, .iso15693, .iso18092],
57
+ delegate: self,
58
+ queue: self.sessionQueue
59
+ )
60
+ if let alertMessage, !alertMessage.isEmpty {
61
+ self.tagReaderSession?.alertMessage = alertMessage
62
+ }
63
+ self.tagReaderSession?.begin()
64
+ } else {
65
+ // Use NFCNDEFReaderSession (default behavior)
66
+ self.ndefReaderSession = NFCNDEFReaderSession(
67
+ delegate: self,
68
+ queue: self.sessionQueue,
69
+ invalidateAfterFirstRead: self.invalidateAfterFirstRead
70
+ )
71
+ if let alertMessage, !alertMessage.isEmpty {
72
+ self.ndefReaderSession?.alertMessage = alertMessage
73
+ }
74
+ self.ndefReaderSession?.begin()
47
75
  }
48
- self.readerSession?.begin()
49
76
  }
50
77
 
51
78
  call.resolve()
@@ -54,15 +81,17 @@ public class NfcPlugin: CAPPlugin, CAPBridgedPlugin {
54
81
 
55
82
  @objc public func stopScanning(_ call: CAPPluginCall) {
56
83
  DispatchQueue.main.async {
57
- self.readerSession?.invalidate()
58
- self.readerSession = nil
84
+ self.ndefReaderSession?.invalidate()
85
+ self.ndefReaderSession = nil
86
+ self.tagReaderSession?.invalidate()
87
+ self.tagReaderSession = nil
59
88
  self.currentTag = nil
60
89
  }
61
90
  call.resolve()
62
91
  }
63
92
 
64
93
  @objc public func write(_ call: CAPPluginCall) {
65
- guard let session = readerSession, let tag = currentTag else {
94
+ guard currentTag != nil else {
66
95
  call.reject("No active NFC session or tag. Call startScanning and present a tag before writing.")
67
96
  return
68
97
  }
@@ -74,21 +103,40 @@ public class NfcPlugin: CAPPlugin, CAPBridgedPlugin {
74
103
 
75
104
  do {
76
105
  let message = try buildMessage(from: rawRecords)
77
- performWrite(message: message, on: tag, session: session, call: call)
106
+ performWriteToCurrentTag(message: message, call: call)
78
107
  } catch {
79
108
  call.reject("Invalid NDEF records payload.", nil, error)
80
109
  }
81
110
  }
82
111
 
83
112
  @objc public func erase(_ call: CAPPluginCall) {
84
- guard let session = readerSession, let tag = currentTag else {
113
+ guard currentTag != nil else {
85
114
  call.reject("No active NFC session or tag. Call startScanning and present a tag before erasing.")
86
115
  return
87
116
  }
88
117
 
89
118
  let emptyRecord = NFCNDEFPayload(format: .empty, type: Data(), identifier: Data(), payload: Data())
90
119
  let message = NFCNDEFMessage(records: [emptyRecord])
91
- performWrite(message: message, on: tag, session: session, call: call)
120
+ performWriteToCurrentTag(message: message, call: call)
121
+ }
122
+
123
+ private func performWriteToCurrentTag(message: NFCNDEFMessage, call: CAPPluginCall) {
124
+ guard let tag = currentTag else {
125
+ call.reject("No active NFC session or tag.")
126
+ return
127
+ }
128
+
129
+ if let ndefSession = ndefReaderSession {
130
+ // For NDEF session, we need to connect to the tag first
131
+ performWrite(message: message, on: tag, session: ndefSession, call: call)
132
+ } else if tagReaderSession != nil {
133
+ // For Tag session, tag remains connected from discovery
134
+ // Note: If the tag is removed and re-presented, the session will detect it as a new tag
135
+ // and performWriteToTag may fail. Users should keep the tag in place after detection.
136
+ performWriteToTag(message: message, on: tag, call: call)
137
+ } else {
138
+ call.reject("No active NFC session.")
139
+ }
92
140
  }
93
141
 
94
142
  @objc public func makeReadOnly(_ call: CAPPluginCall) {
@@ -128,6 +176,18 @@ public class NfcPlugin: CAPPlugin, CAPBridgedPlugin {
128
176
  ])
129
177
  }
130
178
 
179
+ @objc public func isSupported(_ call: CAPPluginCall) {
180
+ #if targetEnvironment(simulator)
181
+ call.resolve([
182
+ "supported": false
183
+ ])
184
+ #else
185
+ call.resolve([
186
+ "supported": NFCNDEFReaderSession.readingAvailable
187
+ ])
188
+ #endif
189
+ }
190
+
131
191
  private func performWrite(message: NFCNDEFMessage, on tag: NFCNDEFTag, session: NFCNDEFReaderSession, call: CAPPluginCall) {
132
192
  session.connect(to: tag) { [weak self] error in
133
193
  guard let self else {
@@ -142,44 +202,48 @@ public class NfcPlugin: CAPPlugin, CAPBridgedPlugin {
142
202
  return
143
203
  }
144
204
 
145
- tag.queryNDEFStatus { status, capacity, statusError in
146
- if let statusError {
147
- DispatchQueue.main.async {
148
- call.reject("Failed to query tag status.", nil, statusError)
149
- }
150
- return
205
+ self.performWriteToTag(message: message, on: tag, call: call)
206
+ }
207
+ }
208
+
209
+ private func performWriteToTag(message: NFCNDEFMessage, on tag: NFCNDEFTag, call: CAPPluginCall) {
210
+ tag.queryNDEFStatus { status, capacity, statusError in
211
+ if let statusError {
212
+ DispatchQueue.main.async {
213
+ call.reject("Failed to query tag status.", nil, statusError)
151
214
  }
215
+ return
216
+ }
152
217
 
153
- switch status {
154
- case .readWrite:
155
- if capacity < message.length {
156
- DispatchQueue.main.async {
157
- call.reject("Tag capacity is insufficient for the provided message.")
158
- }
159
- return
160
- }
161
- tag.writeNDEF(message) { writeError in
162
- DispatchQueue.main.async {
163
- if let writeError {
164
- call.reject("Failed to write NDEF message.", nil, writeError)
165
- } else {
166
- call.resolve()
167
- }
168
- }
169
- }
170
- case .readOnly:
171
- DispatchQueue.main.async {
172
- call.reject("Tag is read only.")
173
- }
174
- case .notSupported:
218
+ switch status {
219
+ case .readWrite:
220
+ if capacity < message.length {
175
221
  DispatchQueue.main.async {
176
- call.reject("Tag does not support NDEF.")
222
+ call.reject("Tag capacity is insufficient for the provided message.")
177
223
  }
178
- @unknown default:
224
+ return
225
+ }
226
+ tag.writeNDEF(message) { writeError in
179
227
  DispatchQueue.main.async {
180
- call.reject("Unknown tag status.")
228
+ if let writeError {
229
+ call.reject("Failed to write NDEF message.", nil, writeError)
230
+ } else {
231
+ call.resolve()
232
+ }
181
233
  }
182
234
  }
235
+ case .readOnly:
236
+ DispatchQueue.main.async {
237
+ call.reject("Tag is read only.")
238
+ }
239
+ case .notSupported:
240
+ DispatchQueue.main.async {
241
+ call.reject("Tag does not support NDEF.")
242
+ }
243
+ @unknown default:
244
+ DispatchQueue.main.async {
245
+ call.reject("Unknown tag status.")
246
+ }
183
247
  }
184
248
  }
185
249
  }
@@ -343,7 +407,7 @@ extension NfcPlugin: NFCNDEFReaderSessionDelegate {
343
407
  self.notifyListeners("nfcStateChange", data: payload, retainUntilConsumed: true)
344
408
  }
345
409
  }
346
- readerSession = nil
410
+ ndefReaderSession = nil
347
411
  }
348
412
 
349
413
  public func readerSession(_ session: NFCNDEFReaderSession, didDetect tags: [NFCNDEFTag]) {
@@ -402,6 +466,140 @@ extension NfcPlugin: NFCNDEFReaderSessionDelegate {
402
466
  }
403
467
  }
404
468
 
469
+ // MARK: - NFCTagReaderSessionDelegate
470
+ extension NfcPlugin: NFCTagReaderSessionDelegate {
471
+ public func tagReaderSessionDidBecomeActive(_ session: NFCTagReaderSession) {
472
+ // Session became active, ready to detect tags
473
+ }
474
+
475
+ public func tagReaderSession(_ session: NFCTagReaderSession, didInvalidateWithError error: Error) {
476
+ currentTag = nil
477
+ let nfcError = error as NSError
478
+
479
+ // Don't emit state change for normal session completion (user canceled)
480
+ // Also check for successful read completion
481
+ if nfcError.code != NFCReaderError.readerSessionInvalidationErrorUserCanceled.rawValue {
482
+ DispatchQueue.main.async {
483
+ let payload: [String: Any] = [
484
+ "status": NFCNDEFReaderSession.readingAvailable ? "NFC_OK" : "NO_NFC",
485
+ "enabled": NFCNDEFReaderSession.readingAvailable
486
+ ]
487
+ self.notifyListeners("nfcStateChange", data: payload, retainUntilConsumed: true)
488
+ }
489
+ }
490
+ tagReaderSession = nil
491
+ }
492
+
493
+ public func tagReaderSession(_ session: NFCTagReaderSession, didDetect tags: [NFCTag]) {
494
+ // Handle multiple tags case - CoreNFC recommends invalidating with a message
495
+ if tags.count > 1 {
496
+ session.invalidate(errorMessage: "More than one tag detected. Please present only one tag.")
497
+ return
498
+ }
499
+
500
+ guard let firstTag = tags.first else {
501
+ return
502
+ }
503
+
504
+ session.connect(to: firstTag) { [weak self] error in
505
+ guard let self else {
506
+ return
507
+ }
508
+
509
+ if let error {
510
+ session.invalidate(errorMessage: "Failed to connect to the tag: \(error.localizedDescription)")
511
+ return
512
+ }
513
+
514
+ // Handle different tag types
515
+ switch firstTag {
516
+ case .miFare(let mifareTag):
517
+ self.processTag(mifareTag, session: session)
518
+ case .iso7816(let iso7816Tag):
519
+ self.processTag(iso7816Tag, session: session)
520
+ case .iso15693(let iso15693Tag):
521
+ self.processTag(iso15693Tag, session: session)
522
+ case .feliCa(let feliCaTag):
523
+ self.processTag(feliCaTag, session: session)
524
+ @unknown default:
525
+ session.invalidate(errorMessage: "Unsupported tag type")
526
+ }
527
+ }
528
+ }
529
+
530
+ private func processTag(_ tag: NFCNDEFTag, session: NFCTagReaderSession) {
531
+ // Try to read NDEF if available, otherwise emit tag with UID only
532
+ tag.queryNDEFStatus { [weak self] status, capacity, error in
533
+ guard let self else {
534
+ return
535
+ }
536
+
537
+ if error == nil && status != .notSupported {
538
+ // Tag supports NDEF, try to read it
539
+ tag.readNDEF { [weak self] message, _ in
540
+ guard let self else {
541
+ return
542
+ }
543
+
544
+ if message == nil {
545
+ // NDEF read failed, still emit tag with UID
546
+ self.emitTagEvent(tag: tag, message: nil, session: session)
547
+ } else {
548
+ // Successfully read NDEF
549
+ self.currentTag = tag
550
+ let event = self.buildEvent(tag: tag, status: status, capacity: capacity, message: message)
551
+ self.notify(event: event)
552
+ if self.invalidateAfterFirstRead {
553
+ session.invalidate()
554
+ }
555
+ }
556
+ }
557
+ } else {
558
+ // Tag doesn't support NDEF or query failed - just emit UID
559
+ self.emitTagEvent(tag: tag, message: nil, session: session)
560
+ }
561
+ }
562
+ }
563
+
564
+ private func emitTagEvent(tag: NFCNDEFTag, message: NFCNDEFMessage?, session: NFCTagReaderSession) {
565
+ // Save the current tag for writing
566
+ currentTag = tag
567
+
568
+ var tagInfo: [String: Any] = [:]
569
+
570
+ // Extract and add the tag ID (UID)
571
+ if let identifierData = extractIdentifier(from: tag) {
572
+ tagInfo["id"] = array(from: identifierData)
573
+ }
574
+
575
+ tagInfo["techTypes"] = detectTechTypes(for: tag)
576
+ tagInfo["type"] = translateType(for: tag)
577
+
578
+ if let message {
579
+ tagInfo["isWritable"] = true
580
+ tagInfo["ndefMessage"] = message.records.map { record in
581
+ [
582
+ "tnf": NSNumber(value: record.typeNameFormat.rawValue),
583
+ "type": array(from: record.type),
584
+ "id": array(from: record.identifier),
585
+ "payload": array(from: record.payload)
586
+ ].compactMapValues { $0 }
587
+ }
588
+ }
589
+
590
+ let event: [String: Any] = [
591
+ "type": message != nil ? "ndef" : "tag",
592
+ "tag": tagInfo
593
+ ]
594
+
595
+ notify(event: event)
596
+
597
+ if invalidateAfterFirstRead {
598
+ session.invalidate()
599
+ }
600
+ }
601
+ }
602
+
405
603
  enum NfcPluginError: Error {
406
604
  case invalidPayload
407
605
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capgo/capacitor-nfc",
3
- "version": "8.0.10",
3
+ "version": "8.0.12",
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",