@icedevml/react-native-host-card-emulation 0.7.1 → 0.7.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.
Files changed (2) hide show
  1. package/README.md +18 -8
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  Host Card Emulation Module for React Native on iOS and Android platforms.
4
4
 
5
5
  > [!NOTE]
6
- > Pull requests are welcome! Please [report an issue](https://github.com/icedevml/react-native-host-card-emulation/issues) if you are running into any difficulties.
6
+ > Pull requests are welcome! Please [report an issue](https://github.com/icedevml/react-native-host-card-emulation/issues) if you encounter any difficulties.
7
7
 
8
8
  > [!IMPORTANT]
9
9
  > As per Apple's policy, **Host Card Emulation feature is only available for users based in the European
@@ -121,7 +121,7 @@ This module provides a uniform low-level HCE API for both mobile platforms.
121
121
  > Check it out in order to understand what methods you can call against the module and what are the expected parameters/return values.
122
122
 
123
123
  > [!NOTE]
124
- > See [Source Code for Demo Application: NDEF NFC Type 4 Tag Emulator (for iOS/Android)](https://github.com/icedevml/react-native-host-card-emulation/tree/master/packages/demo-ndef-app) example for more insignt about the library's API.
124
+ > See [Source Code for Demo Application: NDEF NFC Type 4 Tag Emulator (for iOS/Android)](https://github.com/icedevml/react-native-host-card-emulation/tree/master/packages/demo-ndef-app) example for more insights about the library's API.
125
125
 
126
126
  ### Quick start guide
127
127
 
@@ -140,7 +140,7 @@ This module provides a uniform low-level HCE API for both mobile platforms.
140
140
  }
141
141
  }, []);
142
142
  ```
143
- 2. When user indicates that he/she wants to perform the HCE action, call the following function from the button's onClick routine:
143
+ 2. When the user indicates that he/she wants to perform the HCE action, call the following function from the button's onClick routine:
144
144
  ```typescript
145
145
  await NativeHCEModule.beginSession();
146
146
  ```
@@ -163,8 +163,8 @@ This module provides a uniform low-level HCE API for both mobile platforms.
163
163
  break;
164
164
 
165
165
  case 'readerDeselected':
166
- NativeHCEModule.setSessionAlertMessage('Lost reader'); // only for iOS, no-op in Android
167
- break;
166
+ NativeHCEModule.setSessionAlertMessage('Lost reader'); // only for iOS, no-op in Android
167
+ break;
168
168
  ```
169
169
  For those events, trigger mechanisms are platform dependent:
170
170
  * iOS: The `readerDetected` event will be emitted as soon as the NFC reader's field presence is observed. The `readerDeselected` event will be emitted if the reader is physically disconnected or a non-matching AID is selected by the reader.
@@ -191,7 +191,7 @@ If you need to utilize `NFCPresentmentIntentAssertion` for enhanced user experie
191
191
  ```typescript
192
192
  await NativeHCEModule.acquireExclusiveNFC();
193
193
  ```
194
- This function will acquire an exclusive NFC access for 15 seconds. On system services or other applications will be able to interfere with NFC during that period. For example, the NFC background tag reading will be disabled so it would not generate any distracting notifications.
194
+ This function will acquire an exclusive NFC access for 15 seconds. No system services or other applications will be able to interfere with NFC during that period. For example, the NFC background tag reading will be disabled so it would not generate any distracting notifications.
195
195
 
196
196
  While both session and exclusive NFC access are active, you will receive `readerDetected` events even when the HCE emulation is not started at the time (without any explicit UI being displayed by the system). You can then make a call to `startHCE` to initiate the interaction automatically, without needing the user to click anything beforehand.
197
197
 
@@ -240,7 +240,7 @@ for instance - your app may emulate an NDEF tag even when it's not launched on t
240
240
  }
241
241
  });
242
242
  ```
243
- 2. Register onBackgroundEvent listener in your `runBackground()` function and call to `await NativeHCEModule.initBackgroundHCE()` at the very end, after the event listener is fully set up.
243
+ 2. Implement your background HCE handler by passing an event callback to `processBackgroundHCE()`:
244
244
  ```typescript
245
245
  import { Buffer } from 'buffer/';
246
246
  import {
@@ -248,6 +248,8 @@ for instance - your app may emulate an NDEF tag even when it's not launched on t
248
248
  } from '@icedevml/react-native-host-card-emulation/js/hceBackground';
249
249
 
250
250
  export default async function runBackgroundHCETask(processBackgroundHCE: ProcessBackgroundHCEFunc) {
251
+ // ... initialize any state keeping variables here ...
252
+
251
253
  processBackgroundHCE(async (event, respondAPDU) => {
252
254
  switch (event.type) {
253
255
  /* ... background HCE event handler here ... */
@@ -255,7 +257,7 @@ for instance - your app may emulate an NDEF tag even when it's not launched on t
255
257
  });
256
258
  }
257
259
  ```
258
- 3. Cleanup your event listener in `readerDeselected` -- this is obligatory because lack of proper cleanup will result in bugs and unexpected behavior.
260
+ 3. Whenever you receive `readerDeselected` event, cleanup any side effects (deallocate resources, reset the state back to initial) -- this is obligatory because lack of proper cleanup will result in bugs and unexpected behavior.
259
261
  ```typescript
260
262
  // inside processBackgroundHCE handler's switch
261
263
  case 'readerDeselected':
@@ -276,6 +278,14 @@ for instance - your app may emulate an NDEF tag even when it's not launched on t
276
278
  break;
277
279
  ```
278
280
 
281
+ > [!WARNING]
282
+ > Please note that under some circumstances you might find that your `runBackgroundHCETask()` is running in a few instances concurrently.
283
+ > An example of such situation could be when you receive a C-APDU and the reader rapidly restarts the NFC field and reselects your application
284
+ > before you manage to respond to the original command. Thus, you should not use any global variables to track the state of your app.
285
+ >
286
+ > The library automatically identifies stale (deselected) background tasks. For such stale tasks, any subsequent calls to `await respondAPDU()`
287
+ > will throw an error to prevent communication glitches.
288
+
279
289
  ### More resources
280
290
 
281
291
  * [Module's API specification](https://github.com/icedevml/react-native-host-card-emulation/tree/master/packages/host-card-emulation/js)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@icedevml/react-native-host-card-emulation",
3
- "version": "0.7.1",
3
+ "version": "0.7.2",
4
4
  "description": "Host Card Emulation (HCE) React Native Turbo Module for iOS and Android platforms.",
5
5
  "react-native": "js/index",
6
6
  "source": "js/index",