react-native-nfc-manager 3.14.2 → 3.14.3
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 +138 -186
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -10,29 +10,93 @@ Contributions are welcome!
|
|
|
10
10
|
|
|
11
11
|
Made with ❤️ by [whitedogg13](https://github.com/whitedogg13) and [revteltech](https://github.com/revtel)
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
> Special thanks to [javix64](https://github.com/javix64) for restructuring the documentation!
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
## Table of Contents
|
|
16
|
+
|
|
17
|
+
1. [Installation](#installation)
|
|
18
|
+
2. [Getting Started](#gettingstarted)
|
|
19
|
+
3. [Setup](#setup)
|
|
20
|
+
4. [Documentation](#docs)
|
|
21
|
+
5. [Nfc compatibility](#nfccompatibility)
|
|
22
|
+
6. [Usage Concept](#usageconcept)
|
|
23
|
+
7. [API](#api)
|
|
24
|
+
8. [App demo](#appdemo)
|
|
25
|
+
9. [Learn](#learn)
|
|
26
|
+
|
|
27
|
+
## Installation
|
|
28
|
+
|
|
29
|
+
<a name="installation"></a>
|
|
16
30
|
|
|
17
31
|
```shell
|
|
18
32
|
npm i --save react-native-nfc-manager
|
|
19
33
|
```
|
|
20
|
-
|
|
21
|
-
### native part
|
|
34
|
+
### iOS
|
|
22
35
|
|
|
23
36
|
This library use native-modules, so you will need to do `pod install` for iOS:
|
|
24
37
|
|
|
25
38
|
```shell
|
|
26
39
|
cd ios && pod install && cd ..
|
|
27
40
|
```
|
|
41
|
+
### Android
|
|
28
42
|
|
|
29
|
-
|
|
43
|
+
It should be properly auto-linked, so you don't need to do anything.
|
|
30
44
|
|
|
31
45
|
## Setup
|
|
32
46
|
|
|
33
|
-
|
|
47
|
+
<a name="setup"></a>
|
|
48
|
+
|
|
49
|
+
### iOS
|
|
50
|
+
|
|
51
|
+
1. In [apple developer site](https://developer.apple.com/), enable capability for NFC
|
|
52
|
+
|
|
53
|
+

|
|
54
|
+
|
|
55
|
+
2. in Xcode, add `NFCReaderUsageDescription` into your `info.plist`, for example:
|
|
56
|
+
|
|
57
|
+
```
|
|
58
|
+
<key>NFCReaderUsageDescription</key>
|
|
59
|
+
<string>We need to use NFC</string>
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
More info on Apple's [doc](https://developer.apple.com/documentation/bundleresources/information_property_list/nfcreaderusagedescription?language=objc)
|
|
63
|
+
|
|
64
|
+
Additionally, if writing ISO7816 tags add application identifiers (aid) into your `info.plist` as needed like this.
|
|
65
|
+
```
|
|
66
|
+
<key>com.apple.developer.nfc.readersession.iso7816.select-identifiers</key>
|
|
67
|
+
<array>
|
|
68
|
+
<string>D2760000850100</string>
|
|
69
|
+
<string>D2760000850101</string>
|
|
70
|
+
</array>
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
More info on Apple's [doc](https://developer.apple.com/documentation/corenfc/nfciso7816tag)
|
|
74
|
+
|
|
75
|
+
An incomplete list of aid's can be found here. [Application identifier](https://www.eftlab.com/knowledge-base/211-emv-aid-rid-pix/)
|
|
76
|
+
|
|
77
|
+
3. in Xcode's `Signing & Capabilities` tab, make sure `Near Field Communication Tag Reading` capability had been added, like this:
|
|
78
|
+
|
|
79
|
+

|
|
80
|
+
|
|
81
|
+
If this is the first time you toggle the capabilities, the Xcode will generate a `<your-project>.entitlement` file for you:
|
|
82
|
+
|
|
83
|
+

|
|
34
84
|
|
|
35
|
-
|
|
85
|
+
4. in Xcode, review the generated entitlement. It should look like this:
|
|
86
|
+
|
|
87
|
+

|
|
88
|
+
|
|
89
|
+
More info on Apple's [doc](https://developer.apple.com/documentation/bundleresources/entitlements/com_apple_developer_nfc_readersession_formats?language=objc)
|
|
90
|
+
|
|
91
|
+
### Android
|
|
92
|
+
|
|
93
|
+
Simple add `uses-permission` into your `AndroidManifest.xml`:
|
|
94
|
+
|
|
95
|
+
```xml
|
|
96
|
+
<uses-permission android:name="android.permission.NFC" />
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
#### **Support Android 12**
|
|
36
100
|
|
|
37
101
|
We start to support Android 12 from `v3.11.1`, and you will need to update `compileSdkVersion` to `31`, otherwise the build will fail:
|
|
38
102
|
|
|
@@ -51,31 +115,12 @@ The reason for this is because Android puts new limitation on [PendingIntent](ht
|
|
|
51
115
|
|
|
52
116
|
> The original issue is [here](https://github.com/revtel/react-native-nfc-manager/issues/469)
|
|
53
117
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
### **[Demo App] NfcOpenReWriter**
|
|
57
|
-
|
|
58
|
-
We have a full featured NFC utility app using this library available for download.
|
|
118
|
+
If you don't care about **Android 12** for now, you can use **`v3.11.0`** as a short term solution.
|
|
59
119
|
|
|
60
|
-
<a href='https://apps.apple.com/tw/app/nfc-rewriter/id1551243964' target='_blank'>
|
|
61
|
-
<img alt="react-native-nfc-rewriter" src="./images/Apple-App-Store-Icon.png" width="250">
|
|
62
|
-
</a>
|
|
63
|
-
|
|
64
|
-
</br>
|
|
65
|
-
|
|
66
|
-
<a href='https://play.google.com/store/apps/details?id=com.washow.nfcopenrewriter' target='_blank'>
|
|
67
|
-
<img alt="react-native-nfc-rewriter" src="./images/google-play-icon.jpeg" width="250">
|
|
68
|
-
</a>
|
|
69
|
-
|
|
70
|
-
It also open sourced in this repo: [React Native NFC ReWriter App](https://github.com/revtel/react-native-nfc-rewriter)
|
|
71
|
-
|
|
72
|
-
## Learn
|
|
73
120
|
|
|
74
|
-
|
|
75
|
-
- Free course (1 hour) about basic NFC setup and concept [here](https://www.youtube.com/watch?v=rAS-DvNUFck)
|
|
76
|
-
- Full course (3 hours) for more (NDEF, Deep Linking, NTAG password protection, signature with UID) [here](https://www.newline.co/courses/newline-guide-to-nfcs-with-react-native)
|
|
121
|
+
## Getting Started
|
|
77
122
|
|
|
78
|
-
|
|
123
|
+
<a name="gettingstarted"></a>
|
|
79
124
|
|
|
80
125
|
The simplest (and most common) use case for this library is to read `NFC` tags containing `NDEF`, which can be achieved via the following codes:
|
|
81
126
|
|
|
@@ -123,201 +168,108 @@ const styles = StyleSheet.create({
|
|
|
123
168
|
export default App;
|
|
124
169
|
```
|
|
125
170
|
|
|
126
|
-
Pleaes notice when running above codes, iOS and Android has different behaviors:
|
|
127
171
|
|
|
128
|
-
- iOS will pop up a system scanning UI
|
|
129
|
-
- Android provides **NO** system scanning UI
|
|
130
172
|
|
|
131
|
-
|
|
173
|
+
## DOCUMENTATION
|
|
132
174
|
|
|
133
|
-
|
|
175
|
+
<a name="docs"></a>
|
|
134
176
|
|
|
135
|
-
|
|
177
|
+
Check the full documentation that contains `examples`, `faq` and other topics like `Expo` in our [Wiki](https://github.com/revtel/react-native-nfc-manager/wiki)
|
|
136
178
|
|
|
137
|
-
|
|
138
|
-
import NfcManager, {NfcTech} from 'react-native-nfc-manager';
|
|
179
|
+
## Nfc Compatibility
|
|
139
180
|
|
|
140
|
-
|
|
141
|
-
// You can call it like this:
|
|
142
|
-
// `const nfcTag = await listenToNfcEventOnce()`
|
|
143
|
-
|
|
144
|
-
function listenToNfcEventOnce() {
|
|
145
|
-
const cleanUp = () => {
|
|
146
|
-
NfcManager.setEventListener(NfcEvents.DiscoverTag, null);
|
|
147
|
-
NfcManager.setEventListener(NfcEvents.SessionClosed, null);
|
|
148
|
-
};
|
|
149
|
-
|
|
150
|
-
return new Promise((resolve) => {
|
|
151
|
-
let tagFound = null;
|
|
152
|
-
|
|
153
|
-
NfcManager.setEventListener(NfcEvents.DiscoverTag, (tag) => {
|
|
154
|
-
tagFound = tag;
|
|
155
|
-
resolve(tagFound);
|
|
156
|
-
NfcManager.unregisterTagEvent();
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
NfcManager.setEventListener(NfcEvents.SessionClosed, () => {
|
|
160
|
-
cleanUp();
|
|
161
|
-
if (!tagFound) {
|
|
162
|
-
resolve();
|
|
163
|
-
}
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
NfcManager.registerTagEvent();
|
|
167
|
-
});
|
|
168
|
-
}
|
|
169
|
-
```
|
|
170
|
-
|
|
171
|
-
As you can see, the above approach is more verbose and hard-to-read, so we recommend using `NfcManager.requestTechnology` instead of `NfcManager.registerTagEvent` in your application.
|
|
172
|
-
|
|
173
|
-
## Advanced Usage Concept
|
|
174
|
-
|
|
175
|
-
In higher level, there're 4 steps to use this library:
|
|
181
|
+
<a name="nfccompatibility"></a>
|
|
176
182
|
|
|
177
|
-
|
|
183
|
+
|NFC Technologies | Android | iOS |
|
|
184
|
+
|--- |--- |--- |
|
|
185
|
+
| `Ndef` | ✅ | ✅ |
|
|
186
|
+
| `NfcA` | ✅ | ✅ |
|
|
187
|
+
| `IsoDep` | ✅ | ✅ |
|
|
188
|
+
| `NfcB` | ✅ | ❌ |
|
|
189
|
+
| `NfcF` | ✅ | ❌ |
|
|
190
|
+
| `NfcV` | ✅ | ❌ |
|
|
191
|
+
| `MifareClassic` | ✅ | ❌ |
|
|
192
|
+
| `MifareUltralight`| ✅ | ❌ |
|
|
193
|
+
| `MifareIOS` | ❌ | ✅ |
|
|
194
|
+
| `Iso15693IOS` | ❌ | ✅ |
|
|
195
|
+
| `FelicaIOS` | ❌ | ✅ |
|
|
178
196
|
|
|
179
|
-
|
|
180
|
-
- `NfcA`
|
|
181
|
-
- `NfcB` (Android-only)
|
|
182
|
-
- `NfcF` (Android-only)
|
|
183
|
-
- `NfcV` (Android-only)
|
|
184
|
-
- `IsoDep`
|
|
185
|
-
- `MifareClassic` (Android-only)
|
|
186
|
-
- `MifareUltralight` (Android-only)
|
|
187
|
-
- `MifareIOS` (ios-only)
|
|
188
|
-
- `Iso15693IOS` (ios-only)
|
|
189
|
-
- `FelicaIOS` (ios-only)
|
|
197
|
+
## Usage concept
|
|
190
198
|
|
|
191
|
-
|
|
199
|
+
<a name="usageconcept"></a>
|
|
192
200
|
|
|
193
|
-
|
|
194
|
-
- `nfcAHandler` (for `NfcA` tech)
|
|
195
|
-
- `isoDepHandler` (for `IsoDep` tech)
|
|
196
|
-
- `iso15693HandlerIOS` (for `Iso15693IOS` tech)
|
|
197
|
-
- `mifareClassicHandlerAndroid` (for `mifareClassic` tech)
|
|
198
|
-
- `mifareUltralightHandlerAndroid` (for `mifareUltralight` tech)
|
|
199
|
-
- ... and so on
|
|
200
|
-
|
|
201
|
-
3. call specific methods on the NFC technology handler (for example `NfcManager.ndefHandler.writeNdefMessage`). To view all available methods for some tech handler, check out the [API List](index.d.ts)
|
|
201
|
+
In higher level, there're 4 steps to use this library:
|
|
202
202
|
|
|
203
|
-
|
|
203
|
+
0. (Recommended but not necessary) Before all next steps, use `NfcManager.start()` to start listen a tag.
|
|
204
204
|
|
|
205
|
-
## Advanced Usage Example: NDEF-Writing
|
|
206
205
|
|
|
207
|
-
|
|
206
|
+
1. Request your particular NFC technologies through `NfcManager.requestTechnology`. Let's request `Ndef` techonogy.
|
|
208
207
|
|
|
209
208
|
```javascript
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
async function writeNdef({type, value}) {
|
|
213
|
-
let result = false;
|
|
209
|
+
NfcManager.requestTechnology(NfcTech.Ndef);
|
|
210
|
+
```
|
|
214
211
|
|
|
215
|
-
|
|
216
|
-
// STEP 1
|
|
217
|
-
await NfcManager.requestTechnology(NfcTech.Ndef);
|
|
212
|
+
2. Select the proper NFC technology handler, which is implemented as getter in main `NfcManager` object.
|
|
218
213
|
|
|
219
|
-
|
|
214
|
+
```javascript
|
|
215
|
+
NfcManager.ndefHandler
|
|
216
|
+
```
|
|
220
217
|
|
|
221
|
-
|
|
222
|
-
await NfcManager.ndefHandler // STEP 2
|
|
223
|
-
.writeNdefMessage(bytes); // STEP 3
|
|
224
|
-
result = true;
|
|
225
|
-
}
|
|
226
|
-
} catch (ex) {
|
|
227
|
-
console.warn(ex);
|
|
228
|
-
} finally {
|
|
229
|
-
// STEP 4
|
|
230
|
-
NfcManager.cancelTechnologyRequest();
|
|
231
|
-
}
|
|
218
|
+
3. Call specific methods on the NFC technology handler.
|
|
232
219
|
|
|
233
|
-
|
|
234
|
-
|
|
220
|
+
```javascript
|
|
221
|
+
NfcManager.ndefHandler.getNdefMessage()
|
|
235
222
|
```
|
|
236
223
|
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
Here's another example to read a Mifare Ultralight tag:
|
|
224
|
+
4. Clean up your tech registration through:
|
|
240
225
|
|
|
241
226
|
```javascript
|
|
242
|
-
|
|
243
|
-
let mifarePages = [];
|
|
244
|
-
|
|
245
|
-
try {
|
|
246
|
-
// STEP 1
|
|
247
|
-
let reqMifare = await NfcManager.requestTechnology(
|
|
248
|
-
NfcTech.MifareUltralight,
|
|
249
|
-
);
|
|
250
|
-
|
|
251
|
-
const readLength = 60;
|
|
252
|
-
const mifarePagesRead = await Promise.all(
|
|
253
|
-
[...Array(readLength).keys()].map(async (_, i) => {
|
|
254
|
-
const pages = await NfcManager.mifareUltralightHandlerAndroid // STEP 2
|
|
255
|
-
.mifareUltralightReadPages(i * 4); // STEP 3
|
|
256
|
-
mifarePages.push(pages);
|
|
257
|
-
}),
|
|
258
|
-
);
|
|
259
|
-
} catch (ex) {
|
|
260
|
-
console.warn(ex);
|
|
261
|
-
} finally {
|
|
262
|
-
// STEP 4
|
|
263
|
-
NfcManager.cancelTechnologyRequest();
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
return mifarePages;
|
|
267
|
-
}
|
|
227
|
+
NfcManager.cancelTechnologyRequest()
|
|
268
228
|
```
|
|
269
229
|
|
|
270
|
-
To see more examples, please see [React Native NFC ReWriter App](https://github.com/revtel/react-native-nfc-rewriter)
|
|
271
230
|
|
|
272
231
|
## API
|
|
273
232
|
|
|
274
|
-
|
|
233
|
+
<a name="api"></a>
|
|
275
234
|
|
|
276
|
-
|
|
235
|
+
The following table shows the handler for each technology, so if you need to use a technology, go to [index.d.ts](index.d.ts) and search for it.
|
|
277
236
|
|
|
278
|
-
|
|
237
|
+
|NFC Technologies | Handlers |
|
|
238
|
+
|--- |--- |
|
|
239
|
+
| `Ndef` | `NdefHandler` |
|
|
240
|
+
| `NfcA` | `NfcAHandler` |
|
|
241
|
+
| `IsoDep` | `IsoDepHandler` |
|
|
242
|
+
| `NfcB` | - |
|
|
243
|
+
| `NfcF` | - |
|
|
244
|
+
| `NfcV` | `NfcVHandler` |
|
|
245
|
+
| `MifareClassic` | `MifareClassicHandlerAndroid` |
|
|
246
|
+
| `MifareUltralight`| `MifareUltralightHandlerAndroid` |
|
|
247
|
+
| `MifareIOS` | - |
|
|
248
|
+
| `Iso15693IOS` | `Iso15693HandlerIOS` |
|
|
249
|
+
| `FelicaIOS` | - |
|
|
279
250
|
|
|
280
|
-
## Expo
|
|
281
251
|
|
|
282
|
-
|
|
252
|
+
## App Demo - NfcOpenReWriter
|
|
283
253
|
|
|
284
|
-
|
|
254
|
+
<a name="appdemo"></a>
|
|
285
255
|
|
|
286
|
-
|
|
287
|
-
{
|
|
288
|
-
"expo": {
|
|
289
|
-
"plugins": ["react-native-nfc-manager"]
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
```
|
|
256
|
+
We have a full featured NFC utility app using this library available for download. The source code is here: [**React Native NFC ReWriter App**](https://github.com/revtel/react-native-nfc-rewriter)
|
|
293
257
|
|
|
294
|
-
|
|
258
|
+
<a href='https://apps.apple.com/tw/app/nfc-rewriter/id1551243964' target='_blank'>
|
|
259
|
+
<img alt="react-native-nfc-rewriter" src="./images/Apple-App-Store-Icon.png" width="250">
|
|
260
|
+
</a>
|
|
295
261
|
|
|
296
|
-
>
|
|
262
|
+
</br>
|
|
297
263
|
|
|
298
|
-
|
|
264
|
+
<a href='https://play.google.com/store/apps/details?id=com.washow.nfcopenrewriter' target='_blank'>
|
|
265
|
+
<img alt="react-native-nfc-rewriter" src="./images/google-play-icon.jpeg" width="250">
|
|
266
|
+
</a>
|
|
299
267
|
|
|
300
|
-
|
|
268
|
+
## Learn
|
|
301
269
|
|
|
302
|
-
|
|
303
|
-
- `selectIdentifiers` (_string[]_): Sets the iOS [`com.apple.developer.nfc.readersession.iso7816.select-identifiers`](https://developer.apple.com/documentation/bundleresources/information_property_list/select-identifiers) to a list of supported application IDs (Info.plist).
|
|
304
|
-
- `systemCodes` (_string[]_): Sets the iOS [`com.apple.developer.nfc.readersession.felica.systemcodes`](https://developer.apple.com/documentation/bundleresources/information_property_list/systemcodes) to a user provided list of FeliCa™ system codes that the app supports (Info.plist). Each system code must be a discrete value. The wild card value (`0xFF`) isn't allowed.
|
|
270
|
+
<a name="learn"></a>
|
|
305
271
|
|
|
306
|
-
|
|
272
|
+
We have published a React Native NFC course with [newline.co](https://www.newline.co/), check it out!
|
|
273
|
+
- Free course (1 hour) about basic NFC setup and concept [here](https://www.youtube.com/watch?v=rAS-DvNUFck)
|
|
274
|
+
- Full course (3 hours) for more (NDEF, Deep Linking, NTAG password protection, signature with UID) [here](https://www.newline.co/courses/newline-guide-to-nfcs-with-react-native)
|
|
307
275
|
|
|
308
|
-
```json
|
|
309
|
-
{
|
|
310
|
-
"expo": {
|
|
311
|
-
"plugins": [
|
|
312
|
-
[
|
|
313
|
-
"react-native-nfc-manager",
|
|
314
|
-
{
|
|
315
|
-
"nfcPermission": "Custom permission message",
|
|
316
|
-
"selectIdentifiers": ["A0000002471001"],
|
|
317
|
-
"systemCodes": ["8008"]
|
|
318
|
-
}
|
|
319
|
-
]
|
|
320
|
-
]
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-nfc-manager",
|
|
3
|
-
"version": "3.14.
|
|
3
|
+
"version": "3.14.3",
|
|
4
4
|
"description": "A NFC module for react native.",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"repository": {
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
"typescript": "^4.1.3"
|
|
63
63
|
},
|
|
64
64
|
"dependencies": {
|
|
65
|
-
"@expo/config-plugins": "^
|
|
65
|
+
"@expo/config-plugins": "^6.0.1"
|
|
66
66
|
},
|
|
67
67
|
"scripts": {
|
|
68
68
|
"lint": "eslint .",
|