react-native-nfc-manager 3.14.2 → 3.14.4

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 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
- ## Install
13
+ > Special thanks to [javix64](https://github.com/javix64) for restructuring the documentation!
14
14
 
15
- ### javascript part
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
- For Android, it should be properly auto-linked, so you don't need to do anything.
43
+ It should be properly auto-linked, so you don't need to do anything.
30
44
 
31
45
  ## Setup
32
46
 
33
- Please see [here](setup.md)
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
+ ![enable capability](./images/enable-capability.png "enable capability")
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
+ ![xcode-add-capability](./images/xcode-capability.png "xcode capability")
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
+ ![xcode-add-entitlement](./images/xcode-entitlement.png "xcode entitlement")
34
84
 
35
- ### **Android 12**
85
+ 4. in Xcode, review the generated entitlement. It should look like this:
86
+
87
+ ![edit entitlement](./images/edit-entitlement.png "edit entitlement")
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
- BTW, if you don't care about **Android 12** for now, you can use **`v3.11.0`** as a short term solution.
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
- We have published a React Native NFC course with [newline.co](https://www.newline.co/), check it out!
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
- ## Usage
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
- Regarding the system scannning UI, both platforms should be able to scan your NFC tags succesfully and print out its content.
173
+ ## DOCUMENTATION
132
174
 
133
- ### Old Style (registerTagEvent) To Scan NFC Tags
175
+ <a name="docs"></a>
134
176
 
135
- There's an alterntaive style to scan NFC tags through `NfcManager.registerTagEvent`, like this:
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
- ```javascript
138
- import NfcManager, {NfcTech} from 'react-native-nfc-manager';
179
+ ## Nfc Compatibility
139
180
 
140
- // The following function resolves to a NFC Tag object using old event listener approach.
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
- 1. request your particular NFC technologies through `NfcManager.requestTechnology`, for example:
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
- - `Ndef`
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
- 2. select the proper NFC technology handler, which is implemented as getter in main `NfcManager` object, for example:
199
+ <a name="usageconcept"></a>
192
200
 
193
- - `ndefHandler` (for `Ndef` tech)
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
- 4. clean up your tech registration through `NfcManager.cancelTechnology`
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
- For example, here's an example to write NDEF:
206
+ 1. Request your particular NFC technologies through `NfcManager.requestTechnology`. Let's request `Ndef` techonogy.
208
207
 
209
208
  ```javascript
210
- import NfcManager, {NfcTech, Ndef} from 'react-native-nfc-manager';
211
-
212
- async function writeNdef({type, value}) {
213
- let result = false;
209
+ NfcManager.requestTechnology(NfcTech.Ndef);
210
+ ```
214
211
 
215
- try {
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
- const bytes = Ndef.encodeMessage([Ndef.textRecord('Hello NFC')]);
214
+ ```javascript
215
+ NfcManager.ndefHandler
216
+ ```
220
217
 
221
- if (bytes) {
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
- return result;
234
- }
220
+ ```javascript
221
+ NfcManager.ndefHandler.getNdefMessage()
235
222
  ```
236
223
 
237
- ## Advanced Usage Example: Mifare Ultralight
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
- async function readMifare() {
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
- Please see [here](index.d.ts)
233
+ <a name="api"></a>
275
234
 
276
- ## FAQ
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
- Please see [here](FAQ.md)
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
- > This package cannot be used in the "Expo Go" app because [it requires custom native code](https://docs.expo.io/workflow/customizing/).
252
+ ## App Demo - NfcOpenReWriter
283
253
 
284
- After installing this npm package, add the [config plugin](https://docs.expo.io/guides/config-plugins/) to the [`plugins`](https://docs.expo.io/versions/latest/config/app/#plugins) array of your `app.json` or `app.config.js`:
254
+ <a name="appdemo"></a>
285
255
 
286
- ```json
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
- Next, rebuild your app as described in the ["Adding custom native code"](https://docs.expo.io/workflow/customizing/) guide.
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
- > Notice: This Config Plugin will ensure the minimum Android SDK version is 31.
262
+ </br>
297
263
 
298
- #### Props
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
- The plugin provides props for extra customization. Every time you change the props or plugins, you'll need to rebuild (and `prebuild`) the native app. If no extra properties are added, defaults will be used.
268
+ ## Learn
301
269
 
302
- - `nfcPermission` (_string | false_): Sets the iOS `NFCReaderUsageDescription` permission message to the `Info.plist`. Setting `false` will skip adding the permission. Defaults to `Allow $(PRODUCT_NAME) to interact with nearby NFC devices` (Info.plist).
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
- #### Example
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
- ```
@@ -1315,6 +1315,9 @@ class NfcManager extends ReactContextBaseJavaModule implements ActivityEventList
1315
1315
 
1316
1316
  WritableMap parsed = null;
1317
1317
  Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
1318
+ if (tag == null) {
1319
+ return null;
1320
+ }
1318
1321
  // Parcelable[] messages = intent.getParcelableArrayExtra((NfcAdapter.EXTRA_NDEF_MESSAGES));
1319
1322
 
1320
1323
  synchronized(this) {
package/ios/NfcManager.m CHANGED
@@ -195,15 +195,17 @@ continueUserActivity:(NSUserActivity *)userActivity
195
195
  // inherites from NFCNDEFTag, so we simply allow it to connect
196
196
  if ([tagType isEqualToString:requestType] || [requestType isEqualToString:@"Ndef"]) {
197
197
  RCTResponseSenderBlock pendingCallback = techRequestCallback;
198
- techRequestCallback = nil;
199
198
 
200
199
  [tagSession connectToTag:tag
201
200
  completionHandler:^(NSError *error) {
202
201
  if (error != nil) {
203
- pendingCallback(@[getErrorMessage(error)]);
202
+ NSLog(@"NFCTag restarting polling");
203
+ [self->tagSession restartPolling];
204
204
  return;
205
205
  }
206
206
 
207
+ self->techRequestCallback = nil;
208
+
207
209
  pendingCallback(@[[NSNull null], requestType]);
208
210
  }];
209
211
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-nfc-manager",
3
- "version": "3.14.2",
3
+ "version": "3.14.4",
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": "^4.0.16"
65
+ "@expo/config-plugins": "^6.0.1"
66
66
  },
67
67
  "scripts": {
68
68
  "lint": "eslint .",