@icedevml/react-native-host-card-emulation 0.6.4 → 0.7.1

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
@@ -117,11 +117,11 @@ Afterwards, follow the subsections below for each platform that you need to supp
117
117
  This module provides a uniform low-level HCE API for both mobile platforms.
118
118
 
119
119
  > [!NOTE]
120
- > Raw native module's API specification is available in [packages/host-card-emulation/js](https://github.com/icedevml/react-native-host-card-emulation/blob/master/packages/host-card-emulation/js) subdirectory.
120
+ > Raw native module's API specification is available in [packages/host-card-emulation/js](https://github.com/icedevml/react-native-host-card-emulation/tree/master/packages/host-card-emulation/js) subdirectory.
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 [Demo App's Code (Example Library Usage)](https://github.com/icedevml/react-native-host-card-emulation/blob/master/packages/demo-ndef-app/App.tsx) 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 insignt about the library's API.
125
125
 
126
126
  ### Quick start guide
127
127
 
@@ -200,7 +200,29 @@ This function will throw an exception if:
200
200
  * you are in the cooldown period where you are not allowed to acquire the presentment intent assertion (cooldown is 15 seconds after the previous assertion had expired);
201
201
  * the feature is not supported or the device is not eligible for whatever reason;
202
202
 
203
- Call `NativeHCEModule.isExclusiveNFC()` to check if exclusive NFC access is still active.
203
+ You can check if you are holding an exclusive NFC access by calling:
204
+ ```typescript
205
+ NativeHCEModule.isExclusiveNFC()
206
+ ```
207
+
208
+ Whenever you don't need the exclusive NFC access anymore, call the following function to release the `NFCPresentmentIntentAssertion` object:
209
+ ```typescript
210
+ NativeHCEModule.releaseExclusiveNFC();
211
+ ```
212
+
213
+ > [!TIP]
214
+ > Your exclusive NFC access might time out after exceeding certain allowance period imposed by iOS. Thus, you should periodically poll
215
+ > the `NativeHCEModule.isExclusiveNFC()` value to see if it's still granted. You might decide to navigate into a different UI view
216
+ > once your assertion has timed out, or indicate that in some different way.
217
+
218
+ > [!TIP]
219
+ > Use the React's [AppState](https://reactnative.dev/docs/appstate) listener to see when your app goes out to background.
220
+ > In such event, call `NativeHCEModule.releaseExclusiveNFC()` to explicitly release the exclusive NFC assertion.
221
+ >
222
+ > You must do so in order to avoid running into ambigous states, since the operating system is not going to enforce your
223
+ > exclusive NFC access anyway, as your app has gone to background.
224
+ >
225
+ > You can attempt to acquire the exclusive access assertion again once your app has gone back to foreground (active state).
204
226
 
205
227
  ### Android: Handle HCE calls when the app is not running
206
228
 
@@ -256,5 +278,5 @@ for instance - your app may emulate an NDEF tag even when it's not launched on t
256
278
 
257
279
  ### More resources
258
280
 
259
- * [Module's API specification](https://github.com/icedevml/react-native-host-card-emulation/blob/master/packages/host-card-emulation/js)
260
- * [Demo App's Code (Example Library Usage)](https://github.com/icedevml/react-native-host-card-emulation/blob/master/packages/demo-ndef-app/App.tsx)
281
+ * [Module's API specification](https://github.com/icedevml/react-native-host-card-emulation/tree/master/packages/host-card-emulation/js)
282
+ * [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)
@@ -119,6 +119,12 @@ public class RTNHCEAndroidModule extends NativeHCEModuleSpec {
119
119
  promise.reject("err_platform_unsupported", "acquireExclusiveNFC() is not supported on Android.");
120
120
  }
121
121
 
122
+ @Override
123
+ public void releaseExclusiveNFC() {
124
+ Log.d(TAG, "RTNHCEAndroidModule:releaseExclusiveNFC");
125
+ // unsupported on Android, no-op
126
+ }
127
+
122
128
  @Override
123
129
  public boolean isExclusiveNFC() {
124
130
  Log.d(TAG, "RTNHCEAndroidModule:isExclusiveNFC");
@@ -50,6 +50,12 @@
50
50
  }
51
51
  }
52
52
 
53
+ - (void)releaseExclusiveNFC {
54
+ if (@available(iOS 17.4, *)) {
55
+ [hcemoduleios releaseExclusiveNFC];
56
+ }
57
+ }
58
+
53
59
  - (nonnull NSNumber *)isExclusiveNFC {
54
60
  if (@available(iOS 17.4, *)) {
55
61
  return [hcemoduleios isExclusiveNFC] ? @1 : @0;
@@ -90,6 +96,10 @@
90
96
  return @0;
91
97
  }
92
98
 
99
+ - (nonnull NSNumber *)finishBackgroundHCE:(nonnull NSString *)handle {
100
+ return @0;
101
+ }
102
+
93
103
  - (void)startHCE:(nonnull RCTPromiseResolveBlock)resolve reject:(nonnull RCTPromiseRejectBlock)reject {
94
104
  if (@available(iOS 17.4, *)) {
95
105
  return [hcemoduleios startHCEWithResolve:resolve reject:reject];
@@ -38,7 +38,7 @@ extension Data {
38
38
  reject("err_nfc_reader_not_available", "Preflight check failed: NFCReaderSession.readingAvailable is false", nil)
39
39
  return
40
40
  }
41
-
41
+
42
42
  guard CardSession.isSupported else {
43
43
  reject("err_card_session_unsupported", "Preflight check failed: CardSession.isSupported is false", nil)
44
44
  return
@@ -67,6 +67,10 @@ extension Data {
67
67
  }
68
68
  }
69
69
 
70
+ @objc public func releaseExclusiveNFC() {
71
+ self.presentmentIntent = nil
72
+ }
73
+
70
74
  @objc public func isExclusiveNFC() -> Bool {
71
75
  return self.presentmentIntent != nil && self.presentmentIntent!.isValid
72
76
  }
@@ -166,7 +170,7 @@ extension Data {
166
170
  reject("err_illegal_state", "The provided handle is invalid.", nil)
167
171
  return
168
172
  }
169
-
173
+
170
174
  guard let capdu = self.receivedCardAPDU else {
171
175
  reject("err_no_apdu_received", "There is no received APDU to respond to.", nil)
172
176
  return
@@ -47,6 +47,11 @@ export interface Spec extends TurboModule {
47
47
  * Android: Not supported (throws an exception).
48
48
  */
49
49
  acquireExclusiveNFC(): Promise<void>;
50
+ /**
51
+ * iOS: Release NFCPresentmentIntentAssertion object.
52
+ * Android: Not supported (no-op).
53
+ */
54
+ releaseExclusiveNFC(): void;
50
55
  /**
51
56
  * iOS: Whether the NFCPresentmentIntentAssertion is acquired and still valid.
52
57
  * Android: Always false.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@icedevml/react-native-host-card-emulation",
3
- "version": "0.6.4",
3
+ "version": "0.7.1",
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",