You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: packages/native-hce-module/README.md
+63-26Lines changed: 63 additions & 26 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -23,7 +23,17 @@ Make sure that your project has it enabled. Note that the New Architecture is en
23
23
*(no prerequisite steps are required for Android)*
24
24
25
25
## Installation
26
-
Install `@icedevml/react-native-host-card-emulation` package within your React Native project. Then, follow the subsections below for each platform that you need to support.
26
+
Install this package within your React Native project:
Afterwards, follow the subsections below for each platform that you need to support.
27
37
28
38
### iOS
29
39
1. Make sure to set up a proper signing team and bundle identifier in "Signing & Capabilities" configuration section of your project.
@@ -100,30 +110,46 @@ Install `@icedevml/react-native-host-card-emulation` package within your React N
100
110
101
111
This module provides a uniform low-level HCE API for both mobile platforms.
102
112
103
-
1. Subscribe to the event stream (there is a single global event stream for the entire module):
113
+
> [!NOTE]
114
+
> Raw native module's API specification is available in [packages/native-hce-module/js/NativeHCEModule.ts](https://github.com/icedevml/react-native-host-card-emulation/blob/master/packages/native-hce-module/js/NativeHCEModule.ts).
115
+
> Check it out in order to understand what methods you can call against the module and what are the expected parameters/return values.
116
+
117
+
> [!NOTE]
118
+
> See [Demo App's Code (Example Library Usage)](https://github.com/icedevml/react-native-host-card-emulation/blob/master/packages/demo-hce-module-app/App.tsx) example for more insignt about the library's API.
119
+
120
+
### Quick start guide
121
+
122
+
1. Subscribe to the event stream. There is a single global event stream, so you can subscribe early and remain subscribed to events for the entire application's lifetime.
// cleanup the event listener when the effect is unmounted
132
+
return () => {
133
+
removeListener();
108
134
}
109
-
});
135
+
}, []);
110
136
```
111
-
2. When user indicates that he wants to perform the HCE action, call the following function from the button's onClick routine:
137
+
2. When user indicates that he/she wants to perform the HCE action, call the following function from the button's onClick routine:
112
138
```typescript
113
139
awaitNativeHCEModule?.beginSession();
114
140
```
115
-
This will emit `sessionStarted` event on both platforms. You can start the HCE straight from that event:
141
+
This will emit `sessionStarted` event right after the function call, on both iOS and Android platforms. After the session is started, you can decide to start HCE emulation right away in the event handler:
NativeHCEModule?.setSessionAlertMessage('Tap towards the reader'); // only for iOS, no-op in Android
120
146
awaitNativeHCEModule?.startHCE();
121
147
break;
122
148
```
123
-
3.Calling `startHCE()` causes:
124
-
* iOS: Launch of the NFC scan system UI. The smartphone will start listening for C-APDUs from the readers right after that UI appears on screen. The `readerDetected` event will be emitted as soon as the NFC tag 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.
125
-
* Android: No user interface appears (you have to implement it on your own scanning UI, within your app). The `readerDetected` event will be emitted as soon as the first matching SELECT AID command is observed. The `readerDeselected` event will be emitted if the reader is physically disconnected or a non-matching AID is selected by the reader.
126
-
4. Optionally, you can handle `readerDetected` and `readerDeselected events to enhance user's experience.
* iOS: Your smartphone will start listening for C-APDUs (Command APDUs originating from reader devices) right after that function is called, which will be additionally indicated by the operating system popping out the NFC scanning user interface prompt.
151
+
* Android: HCE commands will be forwarded to your application from that point on. No specific user interface is displayed (you have to implement it on your own, within your app).
152
+
3. Optionally, you can handle `readerDetected` and `readerDeselected` events to enhance user's experience.
@@ -134,29 +160,40 @@ This module provides a uniform low-level HCE API for both mobile platforms.
134
160
NativeHCEModule?.setSessionAlertMessage('Lost reader'); // only for iOS, no-op in Android
135
161
break;
136
162
```
137
-
5. Handle CAPDU
163
+
For those events, trigger mechanisms are platform dependent:
164
+
* iOS: The `readerDetected` event will be emitted as soon as the NFC tag 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.
165
+
* Android: The `readerDetected` event will be emitted as soon as the first matching SELECT AID command is observed. The `readerDeselected` event will be emitted if the reader is physically disconnected or a non-matching AID is selected by the reader.
6. (iOS) Optionally, if you need to utilize `NFCPresentmentIntentAssertion` then at any time you can call:
151
-
```typescript
152
-
NativeHCEModule?.acquireExclusiveNFC();
153
-
```
154
-
Which will throw an exception if the presentment intent assertion was already acquired and is still valid
155
-
(usually 15 seconds) or if the cooldown period for acquiring new assertion was not yet expired (usually also 15 seconds).
180
+
You don't have to respond to the APDU right away from within the event handler, but please remember that the reader might time out if you will be lingering with the response for too long.
156
181
157
-
> [!NOTE]
158
-
> See [Demo App's Code (Example Library Usage)](https://github.com/icedevml/react-native-host-card-emulation/blob/master/packages/demo-hce-module-app/App.tsx) example for more insignt about the library's API.
182
+
### iOS: Acquiring exclusive NFC access
183
+
If you need to utilize `NFCPresentmentIntentAssertion` for enhanced user experience, call:
184
+
```typescript
185
+
NativeHCEModule?.acquireExclusiveNFC();
186
+
```
187
+
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.
159
188
160
-
> [!NOTE]
161
-
> Raw native module's API specification is available in [packages/native-hce-module/js/NativeHCEModule.ts](https://github.com/icedevml/react-native-host-card-emulation/blob/master/packages/native-hce-module/js/NativeHCEModule.ts).
162
-
> Check it out in order to understand what methods you can call against the module and what are the expected parameters/return values.
189
+
This function will throw an exception if:
190
+
* the presentment intent assertion was already acquired and is still active;
191
+
* 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);
192
+
* the feature is not supported or the device is not eligible for whatever reason;
193
+
194
+
Call `NativeHCEModule?.isExclusiveNFC()` to check if exclusive NFC access is still active.
195
+
196
+
### More resources
197
+
198
+
* [Module's API specification](https://github.com/icedevml/react-native-host-card-emulation/blob/master/packages/native-hce-module/js/NativeHCEModule.ts)
0 commit comments