@spencerls/react-native-nfc 1.0.8 → 1.0.9
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 -19
- package/README.md +182 -39
- package/dist/index.d.mts +178 -129
- package/dist/index.d.ts +178 -129
- package/dist/index.js +492 -298
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +492 -299
- 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,70 +117,186 @@ 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
|
|
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);
|
|
137
|
+
};
|
|
105
138
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
139
|
+
return <Button title="Scan Tag" onPress={scanTag} />;
|
|
140
|
+
}
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
---
|
|
144
|
+
|
|
145
|
+
## NDEF Write with Builder
|
|
146
|
+
|
|
147
|
+
**Cross-platform:** Works identically on iOS and Android.
|
|
148
|
+
|
|
149
|
+
```tsx
|
|
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
|
+
);
|
|
111
167
|
};
|
|
112
168
|
|
|
113
|
-
return <Button title="
|
|
169
|
+
return <Button title="Write NDEF" onPress={writeNdef} />;
|
|
114
170
|
}
|
|
115
171
|
```
|
|
116
172
|
|
|
117
173
|
---
|
|
118
174
|
|
|
119
|
-
## NDEF Read
|
|
175
|
+
## NDEF Read
|
|
176
|
+
|
|
177
|
+
**Cross-platform:** Works identically on iOS and Android.
|
|
120
178
|
|
|
121
179
|
```tsx
|
|
122
|
-
import {
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
180
|
+
import { nfc } from "@spencerls/react-native-nfc";
|
|
181
|
+
|
|
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
|
+
---
|
|
194
|
+
|
|
195
|
+
## Custom NFC-V Operations
|
|
196
|
+
|
|
197
|
+
**Cross-platform:** Works identically on iOS and Android.
|
|
198
|
+
|
|
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;
|
|
134
219
|
});
|
|
220
|
+
|
|
221
|
+
console.log("Data:", data);
|
|
135
222
|
};
|
|
136
223
|
|
|
137
|
-
return <Button title="
|
|
224
|
+
return <Button title="Read NFC-V" onPress={readCustom} />;
|
|
138
225
|
}
|
|
139
226
|
```
|
|
140
227
|
|
|
141
228
|
---
|
|
142
229
|
|
|
143
|
-
##
|
|
230
|
+
## High-Level NFC-V Operations
|
|
144
231
|
|
|
145
|
-
|
|
232
|
+
**Cross-platform:** Works identically on iOS and Android.
|
|
233
|
+
|
|
234
|
+
```tsx
|
|
146
235
|
import { nfc } from "@spencerls/react-native-nfc";
|
|
147
236
|
|
|
148
|
-
|
|
149
|
-
|
|
237
|
+
export default function NfcVScreen() {
|
|
238
|
+
const readBlock = async () => {
|
|
239
|
+
const data = await nfc.v.readBlock(0);
|
|
240
|
+
console.log("Block 0:", data);
|
|
241
|
+
};
|
|
150
242
|
|
|
151
|
-
|
|
243
|
+
const writeBlock = async () => {
|
|
244
|
+
const data = new Uint8Array([0x01, 0x02, 0x03, 0x04]);
|
|
245
|
+
await nfc.v.writeBlock(0, data);
|
|
246
|
+
};
|
|
152
247
|
|
|
153
|
-
|
|
248
|
+
const getInfo = async () => {
|
|
249
|
+
const info = await nfc.v.getSystemInfo();
|
|
250
|
+
console.log("System Info:", info);
|
|
251
|
+
};
|
|
154
252
|
|
|
155
|
-
|
|
156
|
-
|
|
253
|
+
return (
|
|
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>
|
|
259
|
+
);
|
|
260
|
+
}
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
---
|
|
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
|
|
157
300
|
```
|
|
158
301
|
|
|
159
302
|
---
|
package/dist/index.d.mts
CHANGED
|
@@ -1,105 +1,46 @@
|
|
|
1
1
|
import * as react_native_nfc_manager from 'react-native-nfc-manager';
|
|
2
|
-
import { TagEvent, NfcTech,
|
|
2
|
+
import { NdefRecord, ISOLangCode, TNF, TagEvent, NfcTech, NdefStatus } from 'react-native-nfc-manager';
|
|
3
3
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
4
4
|
import { PropsWithChildren } from 'react';
|
|
5
5
|
|
|
6
|
-
declare
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
6
|
+
declare class Builder {
|
|
7
|
+
static records(b: NdefBuilder): NdefRecord[];
|
|
8
|
+
static message(b: NdefBuilder): number[];
|
|
9
|
+
static record(init: BuildRecordInit): NdefRecord;
|
|
10
|
+
static textRecord(text: string, lang?: ISOLangCode, encoding?: "utf8" | "utf16", id?: string): NdefRecord;
|
|
11
|
+
static uriRecord(uri: string, id?: string): NdefRecord;
|
|
12
|
+
static jsonRecord(payload: string | Uint8Array | number[], id?: string): NdefRecord;
|
|
13
|
+
static mimeRecord(mimeType: string, payload: string | Uint8Array | number[], id?: string): NdefRecord;
|
|
14
|
+
static externalRecord(domain: string, type: string, payload: string | Uint8Array | number[], id?: string): NdefRecord;
|
|
15
|
+
static createEmpty(): NdefRecord;
|
|
14
16
|
}
|
|
15
17
|
|
|
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 };
|
|
18
|
+
type NdefBuilder = (r: typeof Builder) => NdefRecord[];
|
|
19
|
+
interface BuildRecordInit {
|
|
20
|
+
tnf: TNF;
|
|
21
|
+
type: string | number[];
|
|
22
|
+
id?: string | number[];
|
|
23
|
+
payload?: string | number[];
|
|
24
|
+
}
|
|
25
|
+
interface NdefMessageResult {
|
|
26
|
+
ndefMessage: NdefRecord[];
|
|
27
|
+
type: number;
|
|
28
|
+
maxSize: number;
|
|
29
|
+
isWritable: boolean;
|
|
30
|
+
canMakeReadOnly: boolean;
|
|
85
31
|
}
|
|
86
32
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
33
|
+
type SystemInfo = {
|
|
34
|
+
uid?: string;
|
|
35
|
+
dsfid?: number;
|
|
36
|
+
afi?: number;
|
|
37
|
+
numberOfBlocks?: number;
|
|
38
|
+
blockSize?: number;
|
|
39
|
+
icReference?: number;
|
|
40
|
+
manufacturer?: string;
|
|
91
41
|
};
|
|
92
42
|
|
|
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
43
|
type NfcMode = "idle" | "starting" | "active" | "stopping" | "technology";
|
|
102
|
-
|
|
103
44
|
interface NfcState {
|
|
104
45
|
mode: NfcMode;
|
|
105
46
|
tag: TagEvent | null;
|
|
@@ -129,54 +70,162 @@ declare class NfcService {
|
|
|
129
70
|
}
|
|
130
71
|
declare const nfcService: NfcService;
|
|
131
72
|
|
|
73
|
+
declare function readMessage$1(): Promise<NdefMessageResult>;
|
|
74
|
+
declare function write$1(records: NdefRecord[]): Promise<void>;
|
|
75
|
+
|
|
76
|
+
declare const nfcNdefTag: {
|
|
77
|
+
readonly tech: react_native_nfc_manager.NfcTech[];
|
|
78
|
+
readonly readMessage: typeof readMessage$1;
|
|
79
|
+
readonly write: typeof write$1;
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
declare function getStatus(): Promise<{
|
|
83
|
+
status: NdefStatus;
|
|
84
|
+
capacity: number;
|
|
85
|
+
}>;
|
|
86
|
+
declare function readMessage(): Promise<NdefMessageResult>;
|
|
87
|
+
declare function readFull(): Promise<{
|
|
88
|
+
message: NdefMessageResult;
|
|
89
|
+
tag: TagEvent;
|
|
90
|
+
}>;
|
|
91
|
+
declare function write(records: NdefRecord[]): Promise<void>;
|
|
92
|
+
declare function writeText(text: string, lang?: ISOLangCode, encoding?: "utf8" | "utf16", id?: string): Promise<void>;
|
|
93
|
+
declare function writeUri(uri: string, id?: string): Promise<void>;
|
|
94
|
+
declare function writeJson(data: unknown, id?: string): Promise<void>;
|
|
95
|
+
declare function writeMime(mimeType: string, payload: string | Uint8Array | number[], id?: string): Promise<void>;
|
|
96
|
+
declare function writeExternal(domain: string, type: string, payload: string | Uint8Array | number[], id?: string): Promise<void>;
|
|
97
|
+
declare function makeReadOnly(): Promise<void>;
|
|
98
|
+
|
|
99
|
+
declare function getTag$1(): Promise<react_native_nfc_manager.TagEvent>;
|
|
100
|
+
|
|
101
|
+
declare const nfcTag: {
|
|
102
|
+
readonly getTag: typeof getTag$1;
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
declare function getTag(tech: NfcTech | NfcTech[]): Promise<TagEvent>;
|
|
106
|
+
|
|
107
|
+
declare function transceive(bytes: number[]): Promise<number[]>;
|
|
108
|
+
declare function readBlock$1(tagId: string, blockNumber: number): Promise<Uint8Array>;
|
|
109
|
+
declare function readBlocks$1(tagId: string, startBlock: number, endBlock: number): Promise<Uint8Array<ArrayBuffer>>;
|
|
110
|
+
declare function writeBlock$1(tagId: string, blockNumber: number, data: Uint8Array): Promise<void>;
|
|
111
|
+
declare function writeBlocks$1(tagId: string, blockNumber: number, data: Uint8Array[]): Promise<void>;
|
|
112
|
+
declare function getSystemInfo$1(): Promise<SystemInfo>;
|
|
113
|
+
|
|
114
|
+
declare const FLAGS: {
|
|
115
|
+
HIGH_DATA_RATE: number;
|
|
116
|
+
ADDRESSED: number;
|
|
117
|
+
};
|
|
118
|
+
declare const COMMANDS: {
|
|
119
|
+
READ_SINGLE_BLOCK: number;
|
|
120
|
+
WRITE_SINGLE_BLOCK: number;
|
|
121
|
+
GET_SYSTEM_INFO: number;
|
|
122
|
+
};
|
|
123
|
+
/**
|
|
124
|
+
* Combine multiple flag bits into one byte.
|
|
125
|
+
* Example: Flags.ADDRESSED | Flags.HIGH_DATA_RATE
|
|
126
|
+
*/
|
|
127
|
+
declare function buildFlags(...bits: number[]): number;
|
|
128
|
+
/**
|
|
129
|
+
* Convert tag.id hex string (MSB->LSB) into reversed byte array (LSB->MSB)
|
|
130
|
+
* ISO15693 requires reversed UID for addressed commands.
|
|
131
|
+
*/
|
|
132
|
+
declare function reverseUid(tagIdHex: string): number[];
|
|
133
|
+
/**
|
|
134
|
+
* Build READ_SINGLE_BLOCK command.
|
|
135
|
+
* FLAGS: addressed + high data rate by default.
|
|
136
|
+
*/
|
|
137
|
+
declare function buildReadBlock(uidReversed: number[], blockNumber: number): number[];
|
|
138
|
+
/**
|
|
139
|
+
* Build WRITE_SINGLE_BLOCK command.
|
|
140
|
+
* Note: data must match the block size (usually 4 or 8 bytes).
|
|
141
|
+
*/
|
|
142
|
+
declare function buildWriteBlock(uidReversed: number[], blockNumber: number, data: Uint8Array): number[];
|
|
143
|
+
/**
|
|
144
|
+
* Build GET_SYSTEM_INFO command.
|
|
145
|
+
*/
|
|
146
|
+
declare function buildGetSystemInfo(): number[];
|
|
147
|
+
/**
|
|
148
|
+
* Parse a READ_SINGLE_BLOCK response.
|
|
149
|
+
* Response format:
|
|
150
|
+
* - byte[0] = status (0x00 = success)
|
|
151
|
+
* - byte[1..] = block payload bytes
|
|
152
|
+
*/
|
|
153
|
+
declare function parseReadResponse(resp: number[]): Uint8Array;
|
|
154
|
+
/**
|
|
155
|
+
* Parse WRITE_SINGLE_BLOCK response.
|
|
156
|
+
* Successful write has resp[0] === 0x00.
|
|
157
|
+
*/
|
|
158
|
+
declare function parseWriteResponse(resp: number[]): void;
|
|
159
|
+
/**
|
|
160
|
+
* Parse GET_SYSTEM_INFO response.
|
|
161
|
+
* Returns: UID, DSFID, AFI, numberOfBlocks, blockSize, manufacturer
|
|
162
|
+
*/
|
|
163
|
+
declare function parseSystemInfo(resp: number[]): SystemInfo;
|
|
164
|
+
/** Identify common manufacturers based on UID prefix */
|
|
165
|
+
declare function detectManufacturer(uid: string): string;
|
|
166
|
+
|
|
167
|
+
declare const utils_COMMANDS: typeof COMMANDS;
|
|
168
|
+
declare const utils_FLAGS: typeof FLAGS;
|
|
169
|
+
declare const utils_buildFlags: typeof buildFlags;
|
|
170
|
+
declare const utils_buildGetSystemInfo: typeof buildGetSystemInfo;
|
|
171
|
+
declare const utils_buildReadBlock: typeof buildReadBlock;
|
|
172
|
+
declare const utils_buildWriteBlock: typeof buildWriteBlock;
|
|
173
|
+
declare const utils_detectManufacturer: typeof detectManufacturer;
|
|
174
|
+
declare const utils_parseReadResponse: typeof parseReadResponse;
|
|
175
|
+
declare const utils_parseSystemInfo: typeof parseSystemInfo;
|
|
176
|
+
declare const utils_parseWriteResponse: typeof parseWriteResponse;
|
|
177
|
+
declare const utils_reverseUid: typeof reverseUid;
|
|
178
|
+
declare namespace utils {
|
|
179
|
+
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 };
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
declare const nfcVTag: {
|
|
183
|
+
readonly tech: react_native_nfc_manager.NfcTech.NfcV | react_native_nfc_manager.NfcTech[];
|
|
184
|
+
readonly utils: typeof utils;
|
|
185
|
+
readonly transceive: typeof transceive;
|
|
186
|
+
readonly readBlock: typeof readBlock$1;
|
|
187
|
+
readonly readBlocks: typeof readBlocks$1;
|
|
188
|
+
readonly writeBlock: typeof writeBlock$1;
|
|
189
|
+
readonly writeBlocks: typeof writeBlocks$1;
|
|
190
|
+
readonly getSystemInfo: typeof getSystemInfo$1;
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
declare function writeBlock(blockNumber: number, data: Uint8Array): Promise<void>;
|
|
194
|
+
declare function writeBlocks(blockNumber: number, data: Uint8Array[]): Promise<void>;
|
|
195
|
+
declare function readBlock(blockNumber: number): Promise<Uint8Array>;
|
|
196
|
+
declare function readBlocks(startBlock: number, endBlock: number): Promise<Uint8Array>;
|
|
197
|
+
declare function getSystemInfo(): Promise<SystemInfo>;
|
|
198
|
+
|
|
132
199
|
/**
|
|
133
200
|
* NFC root namespace providing access to:
|
|
134
201
|
* - NfcService
|
|
135
202
|
* - ISO15693 NFC-V ops
|
|
136
|
-
* - NFC-A ops
|
|
137
203
|
* - NDEF operations
|
|
138
204
|
*/
|
|
139
205
|
declare const nfc: {
|
|
140
206
|
readonly service: NfcService;
|
|
141
|
-
/** ISO15693 protocol helpers and high-level operations */
|
|
142
207
|
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[]>;
|
|
208
|
+
readonly writeBlock: typeof writeBlock;
|
|
209
|
+
readonly writeBlocks: typeof writeBlocks;
|
|
210
|
+
readonly readBlock: typeof readBlock;
|
|
211
|
+
readonly readBlocks: typeof readBlocks;
|
|
212
|
+
readonly getSystemInfo: typeof getSystemInfo;
|
|
173
213
|
};
|
|
174
|
-
/** NDEF read/write utilities and operations */
|
|
175
214
|
readonly ndef: {
|
|
176
|
-
readonly
|
|
177
|
-
readonly
|
|
178
|
-
readonly
|
|
179
|
-
readonly
|
|
215
|
+
readonly Builder: typeof Builder;
|
|
216
|
+
readonly getStatus: typeof getStatus;
|
|
217
|
+
readonly readMessage: typeof readMessage;
|
|
218
|
+
readonly readFull: typeof readFull;
|
|
219
|
+
readonly write: typeof write;
|
|
220
|
+
readonly writeText: typeof writeText;
|
|
221
|
+
readonly writeUri: typeof writeUri;
|
|
222
|
+
readonly writeJson: typeof writeJson;
|
|
223
|
+
readonly writeMime: typeof writeMime;
|
|
224
|
+
readonly writeExternal: typeof writeExternal;
|
|
225
|
+
readonly makeReadOnly: typeof makeReadOnly;
|
|
226
|
+
};
|
|
227
|
+
readonly tag: {
|
|
228
|
+
readonly getTag: typeof getTag;
|
|
180
229
|
};
|
|
181
230
|
};
|
|
182
231
|
|
|
@@ -203,4 +252,4 @@ declare function useNfcTechnology(): {
|
|
|
203
252
|
runWithTech: (tech: NfcTech | NfcTech[], fn: () => Promise<void>) => Promise<void>;
|
|
204
253
|
};
|
|
205
254
|
|
|
206
|
-
export { type
|
|
255
|
+
export { type BuildRecordInit, type NdefBuilder, type NdefMessageResult, type NfcMode, NfcProvider, type NfcState, type SystemInfo, nfc, nfcNdefTag, nfcService, nfcTag, nfcVTag, useNfc, useNfcContext, useNfcReader, useNfcState, useNfcTechnology };
|