react-native-nfc-manager 3.11.0 → 3.11.1
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
|
@@ -8,7 +8,7 @@ Bring NFC feature to React Native. Inspired by [phonegap-nfc](https://github.com
|
|
|
8
8
|
|
|
9
9
|
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
|
## Install
|
|
14
14
|
|
|
@@ -41,15 +41,14 @@ We have a full featured NFC utility app available for download.
|
|
|
41
41
|
<a href='https://apps.apple.com/tw/app/nfc-rewriter/id1551243964' target='_blank'>
|
|
42
42
|
<img alt="react-native-nfc-rewriter" src="./images/Apple-App-Store-Icon.png" width="250">
|
|
43
43
|
</a>
|
|
44
|
-
<br/>
|
|
45
44
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
### [Bonus] Reconnect.js
|
|
45
|
+
</br>
|
|
49
46
|
|
|
50
|
-
|
|
47
|
+
<a href='https://play.google.com/store/apps/details?id=com.washow.nfcopenrewriter' target='_blank'>
|
|
48
|
+
<img alt="react-native-nfc-rewriter" src="./images/google-play-icon.jpeg" width="250">
|
|
49
|
+
</a>
|
|
51
50
|
|
|
52
|
-
[
|
|
51
|
+
It also open sourced in this repo: [React Native NFC ReWriter App](https://github.com/revtel/react-native-nfc-rewriter)
|
|
53
52
|
|
|
54
53
|
## Basic Usage
|
|
55
54
|
|
|
@@ -163,41 +162,49 @@ async function initNfc() {
|
|
|
163
162
|
|
|
164
163
|
async function readMifare() {
|
|
165
164
|
try {
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
165
|
+
// 0. Request Mifare technology
|
|
166
|
+
let reqMifare = await NfcManager.requestTechnology(
|
|
167
|
+
NfcTech.MifareUltralight,
|
|
168
|
+
);
|
|
169
|
+
if (reqMifare !== 'MifareUltralight') {
|
|
170
|
+
throw new Error(
|
|
171
|
+
'[NFC Read] [ERR] Mifare technology could not be requested',
|
|
172
|
+
);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// 1. Get NFC Tag information
|
|
176
|
+
const nfcTag = await NfcManager.getTag();
|
|
177
|
+
console.log('[NFC Read] [INFO] Tag: ', nfcTag);
|
|
178
|
+
|
|
179
|
+
// 2. Read pages
|
|
180
|
+
const readLength = 60;
|
|
181
|
+
let mifarePages = [];
|
|
182
|
+
const mifarePagesRead = await Promise.all(
|
|
183
|
+
[...Array(readLength).keys()].map(async (_, i) => {
|
|
184
|
+
const pageOffset = i * 4; // 4 Pages are read at once, so offset should be in steps with length 4
|
|
185
|
+
let pages = await NfcManager.mifareUltralightHandlerAndroid.mifareUltralightReadPages(
|
|
186
|
+
pageOffset,
|
|
187
|
+
);
|
|
188
|
+
mifarePages.push(pages);
|
|
189
|
+
console.log(`[NFC Read] [INFO] Mifare Page: ${pageOffset}`, pages);
|
|
190
|
+
//await wait(500); // If Mifare Chip is to slow
|
|
191
|
+
}),
|
|
192
|
+
);
|
|
193
|
+
|
|
194
|
+
// 3. Success
|
|
195
|
+
console.log('[NFC Read] [INFO] Success reading Mifare');
|
|
196
|
+
|
|
197
|
+
// 4. Cleanup
|
|
198
|
+
_cleanup();
|
|
192
199
|
} catch (ex) {
|
|
193
|
-
|
|
194
|
-
|
|
200
|
+
console.warn('[NFC Read] [ERR] Failed Reading Mifare: ', ex);
|
|
201
|
+
_cleanup();
|
|
195
202
|
}
|
|
196
|
-
}
|
|
203
|
+
}
|
|
197
204
|
|
|
198
205
|
function _cleanup() {
|
|
199
|
-
|
|
200
|
-
}
|
|
206
|
+
NfcManager.cancelTechnologyRequest().catch(() => 0);
|
|
207
|
+
}
|
|
201
208
|
```
|
|
202
209
|
|
|
203
210
|
To see more examples, please see [React Native NFC ReWriter App](https://github.com/revtel/react-native-nfc-rewriter)
|
|
@@ -252,3 +259,4 @@ The plugin provides props for extra customization. Every time you change the pro
|
|
|
252
259
|
}
|
|
253
260
|
}
|
|
254
261
|
```
|
|
262
|
+
|
|
@@ -1064,7 +1064,12 @@ class NfcManager extends ReactContextBaseJavaModule implements ActivityEventList
|
|
|
1064
1064
|
Activity activity = getCurrentActivity();
|
|
1065
1065
|
Intent intent = new Intent(activity, activity.getClass());
|
|
1066
1066
|
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
|
1067
|
-
|
|
1067
|
+
|
|
1068
|
+
int flag = 0;
|
|
1069
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
|
1070
|
+
flag = PendingIntent.FLAG_MUTABLE;
|
|
1071
|
+
}
|
|
1072
|
+
return PendingIntent.getActivity(activity, 0, intent, flag);
|
|
1068
1073
|
}
|
|
1069
1074
|
|
|
1070
1075
|
private IntentFilter[] getIntentFilters() {
|