@spencerls/react-native-nfc 1.0.8 → 1.0.10
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/API.md +430 -32
- package/README.md +174 -47
- package/dist/index.d.mts +179 -139
- package/dist/index.d.ts +179 -139
- package/dist/index.js +500 -328
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +497 -329
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,21 +1,45 @@
|
|
|
1
1
|
# @spencerls/react-native-nfc
|
|
2
2
|
|
|
3
|
-
A clean, React-friendly, cross-platform NFC layer built on top of
|
|
3
|
+
A clean, React-friendly, **cross-platform** NFC layer built on top of
|
|
4
4
|
`react-native-nfc-manager`.
|
|
5
5
|
|
|
6
|
+
## 🎯 Truly Cross-Platform
|
|
7
|
+
|
|
8
|
+
Write your NFC code once and it works on **both iOS and Android**.
|
|
9
|
+
The only platform-specific code is the optional Android reader mode configuration.
|
|
10
|
+
Everything else—reading, writing, and all NFC operations—uses the exact same API.
|
|
11
|
+
|
|
6
12
|
This package provides:
|
|
7
13
|
|
|
8
14
|
- A unified NFC service (`nfcService`)
|
|
9
|
-
- High-level protocol namespaces (`nfc.
|
|
15
|
+
- High-level protocol namespaces (`nfc.tag`, `nfc.v`, `nfc.ndef`)
|
|
16
|
+
- Low-level tag modules (`nfcTag`, `nfcVTag`, `nfcNdefTag`)
|
|
10
17
|
- Automatic iOS reader restarts
|
|
11
18
|
- Safe Android reader handling
|
|
12
19
|
- Optional React hooks and provider
|
|
13
|
-
- Technology sessions for NDEF/NfcV
|
|
20
|
+
- Technology sessions for NDEF/NfcV and raw commands
|
|
21
|
+
- Builder pattern for NDEF records
|
|
14
22
|
|
|
15
23
|
The API is designed to be stable, predictable, and easy to use across iOS and Android.
|
|
16
24
|
|
|
17
25
|
---
|
|
18
26
|
|
|
27
|
+
## Platform Support
|
|
28
|
+
|
|
29
|
+
| Feature | iOS | Android |
|
|
30
|
+
|---------|-----|---------|
|
|
31
|
+
| Reader Mode* | ❌ | ✅ |
|
|
32
|
+
| NDEF Read/Write | ✅ | ✅ |
|
|
33
|
+
| NFC-V (ISO15693) | ✅ | ✅ |
|
|
34
|
+
| Technology Sessions | ✅ | ✅ |
|
|
35
|
+
| React Hooks | ✅ | ✅ |
|
|
36
|
+
|
|
37
|
+
**\*Reader Mode** is Android's background NFC scanning API. iOS uses Technology Sessions instead.
|
|
38
|
+
**Platform-specific code:** Only `enableReaderMode_ANDROID()` is Android-specific (no-op on iOS).
|
|
39
|
+
All other APIs work identically on both platforms.
|
|
40
|
+
|
|
41
|
+
---
|
|
42
|
+
|
|
19
43
|
## Installation
|
|
20
44
|
|
|
21
45
|
```bash
|
|
@@ -41,12 +65,14 @@ import { NfcAdapter } from "react-native-nfc-manager";
|
|
|
41
65
|
export default function ScannerScreen() {
|
|
42
66
|
const { mode } = useNfcState();
|
|
43
67
|
|
|
44
|
-
//
|
|
68
|
+
// Platform-specific: Configure Android reader mode (no-op on iOS)
|
|
69
|
+
// Call once, typically at app startup or in useEffect
|
|
45
70
|
nfcService.enableReaderMode_ANDROID(
|
|
46
71
|
NfcAdapter.FLAG_READER_NFC_V |
|
|
47
72
|
NfcAdapter.FLAG_READER_NO_PLATFORM_SOUNDS
|
|
48
73
|
);
|
|
49
74
|
|
|
75
|
+
// Cross-platform: Works identically on iOS and Android
|
|
50
76
|
useNfc((tagId) => {
|
|
51
77
|
console.log("Scanned:", tagId);
|
|
52
78
|
}, {
|
|
@@ -72,10 +98,11 @@ import { NfcAdapter } from "react-native-nfc-manager";
|
|
|
72
98
|
export default function Screen() {
|
|
73
99
|
const { start, stop } = useNfcReader();
|
|
74
100
|
|
|
75
|
-
//
|
|
101
|
+
// Platform-specific: Configure Android reader mode (no-op on iOS)
|
|
76
102
|
nfcService.enableReaderMode_ANDROID(NfcAdapter.FLAG_READER_NFC_V);
|
|
77
103
|
|
|
78
104
|
const begin = () => {
|
|
105
|
+
// Cross-platform: Works identically on iOS and Android
|
|
79
106
|
start(
|
|
80
107
|
(tag) => {
|
|
81
108
|
console.log("Tag:", tag.id);
|
|
@@ -90,90 +117,190 @@ export default function Screen() {
|
|
|
90
117
|
|
|
91
118
|
---
|
|
92
119
|
|
|
93
|
-
##
|
|
120
|
+
## Get Basic Tag Information
|
|
94
121
|
|
|
95
|
-
|
|
96
|
-
Do not pass raw strings.
|
|
122
|
+
**Cross-platform:** Works identically on iOS and Android.
|
|
97
123
|
|
|
98
124
|
```tsx
|
|
99
125
|
import { nfc } from "@spencerls/react-native-nfc";
|
|
100
|
-
import { useNfcTechnology } from "@spencerls/react-native-nfc";
|
|
101
126
|
import { NfcTech } from "react-native-nfc-manager";
|
|
102
127
|
|
|
103
|
-
export function
|
|
104
|
-
const
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
128
|
+
export default function ScanTagButton() {
|
|
129
|
+
const scanTag = async () => {
|
|
130
|
+
const tag = await nfc.tag.getTag([
|
|
131
|
+
NfcTech.NfcA,
|
|
132
|
+
NfcTech.NfcV,
|
|
133
|
+
NfcTech.Ndef,
|
|
134
|
+
]);
|
|
135
|
+
console.log("Tag ID:", tag.id);
|
|
136
|
+
console.log("Tag Type:", tag.type);
|
|
111
137
|
};
|
|
112
138
|
|
|
113
|
-
return <Button title="
|
|
139
|
+
return <Button title="Scan Tag" onPress={scanTag} />;
|
|
114
140
|
}
|
|
115
141
|
```
|
|
116
142
|
|
|
117
143
|
---
|
|
118
144
|
|
|
119
|
-
## NDEF
|
|
145
|
+
## NDEF Write with Builder
|
|
146
|
+
|
|
147
|
+
**Cross-platform:** Works identically on iOS and Android.
|
|
120
148
|
|
|
121
149
|
```tsx
|
|
122
|
-
import {
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
150
|
+
import { nfc } from "@spencerls/react-native-nfc";
|
|
151
|
+
|
|
152
|
+
export default function WriteNdefButton() {
|
|
153
|
+
const writeNdef = async () => {
|
|
154
|
+
await nfc.ndef.write(
|
|
155
|
+
nfc.ndef.Builder.records((B) => [
|
|
156
|
+
B.textRecord("Hello, world!"),
|
|
157
|
+
B.uriRecord("https://www.google.com"),
|
|
158
|
+
B.jsonRecord(
|
|
159
|
+
JSON.stringify({
|
|
160
|
+
name: "John Doe",
|
|
161
|
+
age: 30,
|
|
162
|
+
email: "john.doe@example.com",
|
|
163
|
+
})
|
|
164
|
+
),
|
|
165
|
+
])
|
|
166
|
+
);
|
|
135
167
|
};
|
|
136
168
|
|
|
137
|
-
return <Button title="Write NDEF" onPress={
|
|
169
|
+
return <Button title="Write NDEF" onPress={writeNdef} />;
|
|
138
170
|
}
|
|
139
171
|
```
|
|
140
172
|
|
|
141
173
|
---
|
|
142
174
|
|
|
143
|
-
##
|
|
175
|
+
## NDEF Read
|
|
144
176
|
|
|
145
|
-
|
|
177
|
+
**Cross-platform:** Works identically on iOS and Android.
|
|
178
|
+
|
|
179
|
+
```tsx
|
|
146
180
|
import { nfc } from "@spencerls/react-native-nfc";
|
|
147
181
|
|
|
148
|
-
|
|
149
|
-
|
|
182
|
+
export default function ReadNdefButton() {
|
|
183
|
+
const readNdef = async () => {
|
|
184
|
+
const { message, tag } = await nfc.ndef.readFull();
|
|
185
|
+
console.log("Tag ID:", tag.id);
|
|
186
|
+
console.log("Records:", message.ndefMessage);
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
return <Button title="Read NDEF" onPress={readNdef} />;
|
|
190
|
+
}
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
---
|
|
150
194
|
|
|
151
|
-
|
|
195
|
+
## Custom NFC-V Operations
|
|
152
196
|
|
|
153
|
-
|
|
197
|
+
**Cross-platform:** Works identically on iOS and Android.
|
|
154
198
|
|
|
155
|
-
|
|
156
|
-
nfc
|
|
199
|
+
```tsx
|
|
200
|
+
import { nfc, nfcTag, nfcVTag } from "@spencerls/react-native-nfc";
|
|
201
|
+
|
|
202
|
+
export default function ReadNfcVButton() {
|
|
203
|
+
const readCustom = async () => {
|
|
204
|
+
const data = await nfc.service.withTechnology(nfcVTag.tech, async () => {
|
|
205
|
+
const tag = await nfcTag.getTag();
|
|
206
|
+
if (!tag?.id) throw new Error("No NFC-V tag detected");
|
|
207
|
+
|
|
208
|
+
const buffer = new Uint8Array();
|
|
209
|
+
let offset = 0;
|
|
210
|
+
|
|
211
|
+
// Read blocks 0, 2, 4, 6
|
|
212
|
+
for (let i = 0; i < 8; i += 2) {
|
|
213
|
+
const block = await nfcVTag.readBlock(tag.id, i);
|
|
214
|
+
buffer.set(block, offset);
|
|
215
|
+
offset += block.length;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
return buffer;
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
console.log("Data:", data);
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
return <Button title="Read NFC-V" onPress={readCustom} />;
|
|
225
|
+
}
|
|
157
226
|
```
|
|
158
227
|
|
|
159
228
|
---
|
|
160
229
|
|
|
161
|
-
##
|
|
230
|
+
## High-Level NFC-V Operations
|
|
231
|
+
|
|
232
|
+
**Cross-platform:** Works identically on iOS and Android.
|
|
162
233
|
|
|
163
234
|
```tsx
|
|
164
|
-
import {
|
|
235
|
+
import { nfc } from "@spencerls/react-native-nfc";
|
|
236
|
+
|
|
237
|
+
export default function NfcVScreen() {
|
|
238
|
+
const readBlock = async () => {
|
|
239
|
+
const data = await nfc.v.readBlock(0);
|
|
240
|
+
console.log("Block 0:", data);
|
|
241
|
+
};
|
|
242
|
+
|
|
243
|
+
const writeBlock = async () => {
|
|
244
|
+
const data = new Uint8Array([0x01, 0x02, 0x03, 0x04]);
|
|
245
|
+
await nfc.v.writeBlock(0, data);
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
const getInfo = async () => {
|
|
249
|
+
const info = await nfc.v.getSystemInfo();
|
|
250
|
+
console.log("System Info:", info);
|
|
251
|
+
};
|
|
165
252
|
|
|
166
|
-
export default function App() {
|
|
167
253
|
return (
|
|
168
|
-
<
|
|
169
|
-
<
|
|
170
|
-
|
|
254
|
+
<View>
|
|
255
|
+
<Button title="Read Block" onPress={readBlock} />
|
|
256
|
+
<Button title="Write Block" onPress={writeBlock} />
|
|
257
|
+
<Button title="Get Info" onPress={getInfo} />
|
|
258
|
+
</View>
|
|
171
259
|
);
|
|
172
260
|
}
|
|
173
261
|
```
|
|
174
262
|
|
|
175
263
|
---
|
|
176
264
|
|
|
265
|
+
## API Overview
|
|
266
|
+
|
|
267
|
+
**Cross-platform:** All APIs below work identically on iOS and Android.
|
|
268
|
+
|
|
269
|
+
```ts
|
|
270
|
+
import { nfc, nfcTag, nfcVTag, nfcNdefTag } from "@spencerls/react-native-nfc";
|
|
271
|
+
|
|
272
|
+
// High-level namespace operations (auto-manages technology sessions)
|
|
273
|
+
await nfc.tag.getTag([NfcTech.NfcV]);
|
|
274
|
+
await nfc.v.readBlock(0);
|
|
275
|
+
await nfc.v.writeBlock(0, data);
|
|
276
|
+
await nfc.v.getSystemInfo();
|
|
277
|
+
await nfc.ndef.write(records);
|
|
278
|
+
await nfc.ndef.readMessage();
|
|
279
|
+
await nfc.ndef.readFull();
|
|
280
|
+
|
|
281
|
+
// Low-level tag modules (use inside withTechnology)
|
|
282
|
+
await nfc.service.withTechnology(nfcVTag.tech, async () => {
|
|
283
|
+
const tag = await nfcTag.getTag();
|
|
284
|
+
const block = await nfcVTag.readBlock(tag.id, 0);
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
// NDEF Builder
|
|
288
|
+
const records = nfc.ndef.Builder.records((B) => [
|
|
289
|
+
B.textRecord("Hello"),
|
|
290
|
+
B.uriRecord("https://example.com"),
|
|
291
|
+
B.jsonRecord(JSON.stringify({ key: "value" })),
|
|
292
|
+
B.mimeRecord("text/plain", "data"),
|
|
293
|
+
B.externalRecord("example.com", "type", "payload"),
|
|
294
|
+
]);
|
|
295
|
+
|
|
296
|
+
// Service control
|
|
297
|
+
nfc.service.enableReaderMode_ANDROID(flags); // Android-only (no-op on iOS)
|
|
298
|
+
await nfc.service.startReader(onTag, options); // Cross-platform
|
|
299
|
+
await nfc.service.stopReader(); // Cross-platform
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
---
|
|
303
|
+
|
|
177
304
|
## License
|
|
178
305
|
|
|
179
306
|
MIT © Spencer Smith
|
package/dist/index.d.mts
CHANGED
|
@@ -1,105 +1,44 @@
|
|
|
1
1
|
import * as react_native_nfc_manager from 'react-native-nfc-manager';
|
|
2
|
-
import { TagEvent, NfcTech,
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
2
|
+
import { NdefRecord, ISOLangCode, TNF, TagEvent, NfcTech, NdefStatus } from 'react-native-nfc-manager';
|
|
3
|
+
|
|
4
|
+
declare class Builder {
|
|
5
|
+
static records(b: NdefBuilder): NdefRecord[];
|
|
6
|
+
static message(b: NdefBuilder): number[];
|
|
7
|
+
static record(init: BuildRecordInit): NdefRecord;
|
|
8
|
+
static textRecord(text: string, lang?: ISOLangCode, encoding?: "utf8" | "utf16", id?: string): NdefRecord;
|
|
9
|
+
static uriRecord(uri: string, id?: string): NdefRecord;
|
|
10
|
+
static jsonRecord(payload: string | Uint8Array | number[], id?: string): NdefRecord;
|
|
11
|
+
static mimeRecord(mimeType: string, payload: string | Uint8Array | number[], id?: string): NdefRecord;
|
|
12
|
+
static externalRecord(domain: string, type: string, payload: string | Uint8Array | number[], id?: string): NdefRecord;
|
|
13
|
+
static createEmpty(): NdefRecord;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
type
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
readonly Flags: {
|
|
30
|
-
readonly HIGH_DATA_RATE: 2;
|
|
31
|
-
readonly ADDRESSED: 32;
|
|
32
|
-
};
|
|
33
|
-
readonly Commands: {
|
|
34
|
-
readonly READ_SINGLE_BLOCK: 32;
|
|
35
|
-
readonly WRITE_SINGLE_BLOCK: 33;
|
|
36
|
-
readonly GET_SYSTEM_INFO: 43;
|
|
37
|
-
};
|
|
38
|
-
/**
|
|
39
|
-
* Combine multiple flag bits into one byte.
|
|
40
|
-
* Example: Flags.ADDRESSED | Flags.HIGH_DATA_RATE
|
|
41
|
-
*/
|
|
42
|
-
readonly flags: (...bits: number[]) => number;
|
|
43
|
-
/**
|
|
44
|
-
* Convert tag.id hex string (MSB->LSB) into reversed byte array (LSB->MSB)
|
|
45
|
-
* ISO15693 requires reversed UID for addressed commands.
|
|
46
|
-
*/
|
|
47
|
-
readonly reverseUid: (tagIdHex: string) => number[];
|
|
48
|
-
/**
|
|
49
|
-
* Build READ_SINGLE_BLOCK command.
|
|
50
|
-
* FLAGS: addressed + high data rate by default.
|
|
51
|
-
*/
|
|
52
|
-
readonly buildReadBlock: (uidReversed: number[], blockNumber: number) => number[];
|
|
53
|
-
/**
|
|
54
|
-
* Build WRITE_SINGLE_BLOCK command.
|
|
55
|
-
* Note: data must match the block size (usually 4 or 8 bytes).
|
|
56
|
-
*/
|
|
57
|
-
readonly buildWriteBlock: (uidReversed: number[], blockNumber: number, data: Uint8Array) => number[];
|
|
58
|
-
/**
|
|
59
|
-
* Build GET_SYSTEM_INFO command.
|
|
60
|
-
*/
|
|
61
|
-
readonly buildGetSystemInfo: (uidReversed: number[]) => number[];
|
|
62
|
-
/**
|
|
63
|
-
* Parse a READ_SINGLE_BLOCK response.
|
|
64
|
-
* Response format:
|
|
65
|
-
* - byte[0] = status (0x00 = success)
|
|
66
|
-
* - byte[1..] = block payload bytes
|
|
67
|
-
*/
|
|
68
|
-
readonly parseReadResponse: (resp: number[]) => Uint8Array;
|
|
69
|
-
/**
|
|
70
|
-
* Parse WRITE_SINGLE_BLOCK response.
|
|
71
|
-
* Successful write has resp[0] === 0x00.
|
|
72
|
-
*/
|
|
73
|
-
readonly parseWriteResponse: (resp: number[]) => void;
|
|
74
|
-
/**
|
|
75
|
-
* Parse GET_SYSTEM_INFO response.
|
|
76
|
-
* Returns: UID, DSFID, AFI, numberOfBlocks, blockSize, manufacturer
|
|
77
|
-
*/
|
|
78
|
-
readonly parseSystemInfo: (resp: number[]) => any;
|
|
79
|
-
/** Identify common manufacturers based on UID prefix */
|
|
80
|
-
readonly detectManufacturer: (uid: string) => string;
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
declare namespace index$1 {
|
|
84
|
-
export { operations$1 as operations, utils$1 as utils };
|
|
16
|
+
type NdefBuilder = (r: typeof Builder) => NdefRecord[];
|
|
17
|
+
interface BuildRecordInit {
|
|
18
|
+
tnf: TNF;
|
|
19
|
+
type: string | number[];
|
|
20
|
+
id?: string | number[];
|
|
21
|
+
payload?: string | number[];
|
|
22
|
+
}
|
|
23
|
+
interface NdefMessageResult {
|
|
24
|
+
ndefMessage: NdefRecord[];
|
|
25
|
+
type: number;
|
|
26
|
+
maxSize: number;
|
|
27
|
+
isWritable: boolean;
|
|
28
|
+
canMakeReadOnly: boolean;
|
|
85
29
|
}
|
|
86
30
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
31
|
+
type SystemInfo = {
|
|
32
|
+
uid?: string;
|
|
33
|
+
dsfid?: number;
|
|
34
|
+
afi?: number;
|
|
35
|
+
numberOfBlocks?: number;
|
|
36
|
+
blockSize?: number;
|
|
37
|
+
icReference?: number;
|
|
38
|
+
manufacturer?: string;
|
|
91
39
|
};
|
|
92
40
|
|
|
93
|
-
declare const utils: {};
|
|
94
|
-
|
|
95
|
-
declare const index_operations: typeof operations;
|
|
96
|
-
declare const index_utils: typeof utils;
|
|
97
|
-
declare namespace index {
|
|
98
|
-
export { index_operations as operations, index_utils as utils };
|
|
99
|
-
}
|
|
100
|
-
|
|
101
41
|
type NfcMode = "idle" | "starting" | "active" | "stopping" | "technology";
|
|
102
|
-
|
|
103
42
|
interface NfcState {
|
|
104
43
|
mode: NfcMode;
|
|
105
44
|
tag: TagEvent | null;
|
|
@@ -129,64 +68,165 @@ declare class NfcService {
|
|
|
129
68
|
}
|
|
130
69
|
declare const nfcService: NfcService;
|
|
131
70
|
|
|
71
|
+
declare function readMessage$1(): Promise<NdefMessageResult>;
|
|
72
|
+
declare function write$1(records: NdefRecord[]): Promise<void>;
|
|
73
|
+
|
|
74
|
+
declare const nfcNdefTag: {
|
|
75
|
+
readonly tech: react_native_nfc_manager.NfcTech[];
|
|
76
|
+
readonly readMessage: typeof readMessage$1;
|
|
77
|
+
readonly write: typeof write$1;
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
declare function getStatus(): Promise<{
|
|
81
|
+
status: NdefStatus;
|
|
82
|
+
capacity: number;
|
|
83
|
+
}>;
|
|
84
|
+
declare function readMessage(): Promise<NdefMessageResult>;
|
|
85
|
+
declare function readFull(): Promise<{
|
|
86
|
+
message: NdefMessageResult;
|
|
87
|
+
tag: TagEvent;
|
|
88
|
+
}>;
|
|
89
|
+
declare function write(records: NdefRecord[]): Promise<void>;
|
|
90
|
+
declare function writeText(text: string, lang?: ISOLangCode, encoding?: "utf8" | "utf16", id?: string): Promise<void>;
|
|
91
|
+
declare function writeUri(uri: string, id?: string): Promise<void>;
|
|
92
|
+
declare function writeJson(data: unknown, id?: string): Promise<void>;
|
|
93
|
+
declare function writeMime(mimeType: string, payload: string | Uint8Array | number[], id?: string): Promise<void>;
|
|
94
|
+
declare function writeExternal(domain: string, type: string, payload: string | Uint8Array | number[], id?: string): Promise<void>;
|
|
95
|
+
declare function makeReadOnly(): Promise<void>;
|
|
96
|
+
|
|
97
|
+
declare function getTag$1(): Promise<react_native_nfc_manager.TagEvent>;
|
|
98
|
+
|
|
99
|
+
declare const nfcTag: {
|
|
100
|
+
readonly getTag: typeof getTag$1;
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
declare function getTag(tech: NfcTech | NfcTech[]): Promise<TagEvent>;
|
|
104
|
+
|
|
105
|
+
declare function transceive(bytes: number[]): Promise<number[]>;
|
|
106
|
+
declare function readBlock$1(tagId: string, blockNumber: number): Promise<Uint8Array>;
|
|
107
|
+
declare function readBlocks$1(tagId: string, startBlock: number, endBlock: number): Promise<Uint8Array<ArrayBuffer>>;
|
|
108
|
+
declare function writeBlock$1(tagId: string, blockNumber: number, data: Uint8Array): Promise<void>;
|
|
109
|
+
declare function writeBlocks$1(tagId: string, blockNumber: number, data: Uint8Array[]): Promise<void>;
|
|
110
|
+
declare function getSystemInfo$1(): Promise<SystemInfo>;
|
|
111
|
+
|
|
112
|
+
declare const FLAGS: {
|
|
113
|
+
HIGH_DATA_RATE: number;
|
|
114
|
+
ADDRESSED: number;
|
|
115
|
+
};
|
|
116
|
+
declare const COMMANDS: {
|
|
117
|
+
READ_SINGLE_BLOCK: number;
|
|
118
|
+
WRITE_SINGLE_BLOCK: number;
|
|
119
|
+
GET_SYSTEM_INFO: number;
|
|
120
|
+
};
|
|
121
|
+
/**
|
|
122
|
+
* Combine multiple flag bits into one byte.
|
|
123
|
+
* Example: Flags.ADDRESSED | Flags.HIGH_DATA_RATE
|
|
124
|
+
*/
|
|
125
|
+
declare function buildFlags(...bits: number[]): number;
|
|
126
|
+
/**
|
|
127
|
+
* Convert tag.id hex string (MSB->LSB) into reversed byte array (LSB->MSB)
|
|
128
|
+
* ISO15693 requires reversed UID for addressed commands.
|
|
129
|
+
*/
|
|
130
|
+
declare function reverseUid(tagIdHex: string): number[];
|
|
131
|
+
/**
|
|
132
|
+
* Build READ_SINGLE_BLOCK command.
|
|
133
|
+
* FLAGS: addressed + high data rate by default.
|
|
134
|
+
*/
|
|
135
|
+
declare function buildReadBlock(uidReversed: number[], blockNumber: number): number[];
|
|
136
|
+
/**
|
|
137
|
+
* Build WRITE_SINGLE_BLOCK command.
|
|
138
|
+
* Note: data must match the block size (usually 4 or 8 bytes).
|
|
139
|
+
*/
|
|
140
|
+
declare function buildWriteBlock(uidReversed: number[], blockNumber: number, data: Uint8Array): number[];
|
|
141
|
+
/**
|
|
142
|
+
* Build GET_SYSTEM_INFO command.
|
|
143
|
+
*/
|
|
144
|
+
declare function buildGetSystemInfo(): number[];
|
|
145
|
+
/**
|
|
146
|
+
* Parse a READ_SINGLE_BLOCK response.
|
|
147
|
+
* Response format:
|
|
148
|
+
* - byte[0] = status (0x00 = success)
|
|
149
|
+
* - byte[1..] = block payload bytes
|
|
150
|
+
*/
|
|
151
|
+
declare function parseReadResponse(resp: number[]): Uint8Array;
|
|
152
|
+
/**
|
|
153
|
+
* Parse WRITE_SINGLE_BLOCK response.
|
|
154
|
+
* Successful write has resp[0] === 0x00.
|
|
155
|
+
*/
|
|
156
|
+
declare function parseWriteResponse(resp: number[]): void;
|
|
157
|
+
/**
|
|
158
|
+
* Parse GET_SYSTEM_INFO response.
|
|
159
|
+
* Returns: UID, DSFID, AFI, numberOfBlocks, blockSize, manufacturer
|
|
160
|
+
*/
|
|
161
|
+
declare function parseSystemInfo(resp: number[]): SystemInfo;
|
|
162
|
+
/** Identify common manufacturers based on UID prefix */
|
|
163
|
+
declare function detectManufacturer(uid: string): string;
|
|
164
|
+
|
|
165
|
+
declare const utils_COMMANDS: typeof COMMANDS;
|
|
166
|
+
declare const utils_FLAGS: typeof FLAGS;
|
|
167
|
+
declare const utils_buildFlags: typeof buildFlags;
|
|
168
|
+
declare const utils_buildGetSystemInfo: typeof buildGetSystemInfo;
|
|
169
|
+
declare const utils_buildReadBlock: typeof buildReadBlock;
|
|
170
|
+
declare const utils_buildWriteBlock: typeof buildWriteBlock;
|
|
171
|
+
declare const utils_detectManufacturer: typeof detectManufacturer;
|
|
172
|
+
declare const utils_parseReadResponse: typeof parseReadResponse;
|
|
173
|
+
declare const utils_parseSystemInfo: typeof parseSystemInfo;
|
|
174
|
+
declare const utils_parseWriteResponse: typeof parseWriteResponse;
|
|
175
|
+
declare const utils_reverseUid: typeof reverseUid;
|
|
176
|
+
declare namespace utils {
|
|
177
|
+
export { utils_COMMANDS as COMMANDS, utils_FLAGS as FLAGS, utils_buildFlags as buildFlags, utils_buildGetSystemInfo as buildGetSystemInfo, utils_buildReadBlock as buildReadBlock, utils_buildWriteBlock as buildWriteBlock, utils_detectManufacturer as detectManufacturer, utils_parseReadResponse as parseReadResponse, utils_parseSystemInfo as parseSystemInfo, utils_parseWriteResponse as parseWriteResponse, utils_reverseUid as reverseUid };
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
declare const nfcVTag: {
|
|
181
|
+
readonly tech: react_native_nfc_manager.NfcTech.NfcV | react_native_nfc_manager.NfcTech[];
|
|
182
|
+
readonly utils: typeof utils;
|
|
183
|
+
readonly transceive: typeof transceive;
|
|
184
|
+
readonly readBlock: typeof readBlock$1;
|
|
185
|
+
readonly readBlocks: typeof readBlocks$1;
|
|
186
|
+
readonly writeBlock: typeof writeBlock$1;
|
|
187
|
+
readonly writeBlocks: typeof writeBlocks$1;
|
|
188
|
+
readonly getSystemInfo: typeof getSystemInfo$1;
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
declare function writeBlock(blockNumber: number, data: Uint8Array): Promise<void>;
|
|
192
|
+
declare function writeBlocks(blockNumber: number, data: Uint8Array[]): Promise<void>;
|
|
193
|
+
declare function readBlock(blockNumber: number): Promise<Uint8Array>;
|
|
194
|
+
declare function readBlocks(startBlock: number, endBlock: number): Promise<Uint8Array>;
|
|
195
|
+
declare function getSystemInfo(): Promise<SystemInfo>;
|
|
196
|
+
|
|
132
197
|
/**
|
|
133
198
|
* NFC root namespace providing access to:
|
|
134
199
|
* - NfcService
|
|
135
200
|
* - ISO15693 NFC-V ops
|
|
136
|
-
* - NFC-A ops
|
|
137
201
|
* - NDEF operations
|
|
138
202
|
*/
|
|
139
203
|
declare const nfc: {
|
|
140
204
|
readonly service: NfcService;
|
|
141
|
-
/** ISO15693 protocol helpers and high-level operations */
|
|
142
205
|
readonly v: {
|
|
143
|
-
readonly
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
};
|
|
149
|
-
readonly Commands: {
|
|
150
|
-
readonly READ_SINGLE_BLOCK: 32;
|
|
151
|
-
readonly WRITE_SINGLE_BLOCK: 33;
|
|
152
|
-
readonly GET_SYSTEM_INFO: 43;
|
|
153
|
-
};
|
|
154
|
-
readonly flags: (...bits: number[]) => number;
|
|
155
|
-
readonly reverseUid: (tagIdHex: string) => number[];
|
|
156
|
-
readonly buildReadBlock: (uidReversed: number[], blockNumber: number) => number[];
|
|
157
|
-
readonly buildWriteBlock: (uidReversed: number[], blockNumber: number, data: Uint8Array) => number[];
|
|
158
|
-
readonly buildGetSystemInfo: (uidReversed: number[]) => number[];
|
|
159
|
-
readonly parseReadResponse: (resp: number[]) => Uint8Array;
|
|
160
|
-
readonly parseWriteResponse: (resp: number[]) => void;
|
|
161
|
-
readonly parseSystemInfo: (resp: number[]) => any;
|
|
162
|
-
readonly detectManufacturer: (uid: string) => string;
|
|
163
|
-
};
|
|
164
|
-
readonly withVTag: <T>(handler: (tag: StrictTagEvent) => Promise<T>) => Promise<T>;
|
|
165
|
-
readonly writeBlockNfcV: (blockNumber: number, data: Uint8Array) => Promise<void>;
|
|
166
|
-
readonly readBlockNfcV: (blockNumber: number) => Promise<Uint8Array<ArrayBufferLike>>;
|
|
167
|
-
readonly getSystemInfoNfcV: () => Promise<any>;
|
|
168
|
-
};
|
|
169
|
-
/** NFC-A / Type 2 helpers and operations */
|
|
170
|
-
readonly a: {
|
|
171
|
-
readonly utils: {};
|
|
172
|
-
readonly transceive: (data: number[]) => Promise<number[]>;
|
|
206
|
+
readonly writeBlock: typeof writeBlock;
|
|
207
|
+
readonly writeBlocks: typeof writeBlocks;
|
|
208
|
+
readonly readBlock: typeof readBlock;
|
|
209
|
+
readonly readBlocks: typeof readBlocks;
|
|
210
|
+
readonly getSystemInfo: typeof getSystemInfo;
|
|
173
211
|
};
|
|
174
|
-
/** NDEF read/write utilities and operations */
|
|
175
212
|
readonly ndef: {
|
|
176
|
-
readonly
|
|
177
|
-
readonly
|
|
178
|
-
readonly
|
|
179
|
-
readonly
|
|
213
|
+
readonly Builder: typeof Builder;
|
|
214
|
+
readonly getStatus: typeof getStatus;
|
|
215
|
+
readonly readMessage: typeof readMessage;
|
|
216
|
+
readonly readFull: typeof readFull;
|
|
217
|
+
readonly write: typeof write;
|
|
218
|
+
readonly writeText: typeof writeText;
|
|
219
|
+
readonly writeUri: typeof writeUri;
|
|
220
|
+
readonly writeJson: typeof writeJson;
|
|
221
|
+
readonly writeMime: typeof writeMime;
|
|
222
|
+
readonly writeExternal: typeof writeExternal;
|
|
223
|
+
readonly makeReadOnly: typeof makeReadOnly;
|
|
224
|
+
};
|
|
225
|
+
readonly tag: {
|
|
226
|
+
readonly getTag: typeof getTag;
|
|
180
227
|
};
|
|
181
228
|
};
|
|
182
229
|
|
|
183
|
-
interface NfcContextValue {
|
|
184
|
-
state: NfcState;
|
|
185
|
-
service: typeof nfcService;
|
|
186
|
-
}
|
|
187
|
-
declare function NfcProvider({ children }: PropsWithChildren): react_jsx_runtime.JSX.Element;
|
|
188
|
-
declare function useNfcContext(): NfcContextValue;
|
|
189
|
-
|
|
190
230
|
declare function useNfc(onTag: (tagId: string) => void, options: {
|
|
191
231
|
cooldownMs?: number;
|
|
192
232
|
}): void;
|
|
@@ -203,4 +243,4 @@ declare function useNfcTechnology(): {
|
|
|
203
243
|
runWithTech: (tech: NfcTech | NfcTech[], fn: () => Promise<void>) => Promise<void>;
|
|
204
244
|
};
|
|
205
245
|
|
|
206
|
-
export { type
|
|
246
|
+
export { type BuildRecordInit, type NdefBuilder, type NdefMessageResult, type NfcMode, type NfcState, type SystemInfo, nfc, nfcNdefTag, nfcService, nfcTag, nfcVTag, useNfc, useNfcReader, useNfcState, useNfcTechnology };
|