Skip to content

Commit b82c46f

Browse files
authored
Update README.md (#50)
1 parent f2eb879 commit b82c46f

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

packages/host-card-emulation/README.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ This module provides a uniform low-level HCE API for both mobile platforms.
128128
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.
129129
```typescript
130130
useEffect(() => {
131-
const subscription = NativeHCEModule?.onEvent(async (event: HCEModuleEvent) => {
131+
const subscription = NativeHCEModule.onEvent(async (event: HCEModuleEvent) => {
132132
switch (event.type) {
133133
/* ... implement event handlers here ... */
134134
}
@@ -142,45 +142,45 @@ This module provides a uniform low-level HCE API for both mobile platforms.
142142
```
143143
2. When user indicates that he/she wants to perform the HCE action, call the following function from the button's onClick routine:
144144
```typescript
145-
await NativeHCEModule?.beginSession();
145+
await NativeHCEModule.beginSession();
146146
```
147147
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:
148148
```typescript
149-
// inside NativeHCEModule?.onEvent handler's switch
149+
// inside NativeHCEModule.onEvent handler's switch
150150
case 'sessionStarted':
151-
NativeHCEModule?.setSessionAlertMessage('Tap towards the reader'); // only for iOS, no-op in Android
152-
await NativeHCEModule?.startHCE();
151+
NativeHCEModule.setSessionAlertMessage('Tap towards the reader'); // only for iOS, no-op in Android
152+
await NativeHCEModule.startHCE();
153153
break;
154154
```
155-
Calling `await NativeHCEModule?.startHCE()` causes:
155+
Calling `await NativeHCEModule.startHCE()` causes:
156156
* 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.
157157
* 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).
158158
3. Optionally, you can handle `readerDetected` and `readerDeselected` events to enhance user's experience.
159159
```typescript
160-
// inside NativeHCEModule?.onEvent handler's switch
160+
// inside NativeHCEModule.onEvent handler's switch
161161
case 'readerDetected':
162-
NativeHCEModule?.setSessionAlertMessage('Reader detected'); // only for iOS, no-op in Android
162+
NativeHCEModule.setSessionAlertMessage('Reader detected'); // only for iOS, no-op in Android
163163
break;
164164

165165
case 'readerDeselected':
166-
NativeHCEModule?.setSessionAlertMessage('Lost reader'); // only for iOS, no-op in Android
166+
NativeHCEModule.setSessionAlertMessage('Lost reader'); // only for iOS, no-op in Android
167167
break;
168168
```
169169
For those events, trigger mechanisms are platform dependent:
170170
* 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.
171171
* 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.
172172
4. Receive incoming C-APDU and respond to it:
173173
```typescript
174-
// inside NativeHCEModule?.onEvent handler's switch
174+
// inside NativeHCEModule.onEvent handler's switch
175175
case 'received':
176-
NativeHCEModule?.setSessionAlertMessage('Keep holding the tag'); // only for iOS, no-op on Android
176+
NativeHCEModule.setSessionAlertMessage('Keep holding the tag'); // only for iOS, no-op on Android
177177

178178
// decode incoming C-APDU to bytes
179179
const capdu = Buffer.from(event.arg!, 'hex');
180180
console.log('Received C-APDU, capdu.toString('hex'));
181181

182182
// for the demo purposes, we always want to respond with [0x0A] + status code 0x9000 (success)
183-
await NativeHCEModule?.respondAPDU(null, Buffer.from([0x0A, 0x90, 0x00], "hex"));
183+
await NativeHCEModule.respondAPDU(null, Buffer.from([0x0A, 0x90, 0x00]).toString("hex"));
184184
break;
185185
```
186186
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.
@@ -189,7 +189,7 @@ This module provides a uniform low-level HCE API for both mobile platforms.
189189
190190
If you need to utilize `NFCPresentmentIntentAssertion` for enhanced user experience, call:
191191
```typescript
192-
NativeHCEModule?.acquireExclusiveNFC();
192+
NativeHCEModule.acquireExclusiveNFC();
193193
```
194194
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.
195195
@@ -198,7 +198,7 @@ This function will throw an exception if:
198198
* 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);
199199
* the feature is not supported or the device is not eligible for whatever reason;
200200
201-
Call `NativeHCEModule?.isExclusiveNFC()` to check if exclusive NFC access is still active.
201+
Call `NativeHCEModule.isExclusiveNFC()` to check if exclusive NFC access is still active.
202202
203203
### Android: Handle HCE calls when the app is not running
204204
@@ -216,7 +216,7 @@ for instance - your app may emulate an NDEF tag even when it's not launched on t
216216
}
217217
});
218218
```
219-
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.
219+
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.
220220
```typescript
221221
import { Buffer } from 'buffer/';
222222
import {

0 commit comments

Comments
 (0)