react-native-nfc-manager 3.13.2 → 3.13.5
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
|
@@ -69,6 +69,12 @@ We have a full featured NFC utility app using this library available for downloa
|
|
|
69
69
|
|
|
70
70
|
It also open sourced in this repo: [React Native NFC ReWriter App](https://github.com/revtel/react-native-nfc-rewriter)
|
|
71
71
|
|
|
72
|
+
## Learn
|
|
73
|
+
|
|
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)
|
|
77
|
+
|
|
72
78
|
## Usage
|
|
73
79
|
|
|
74
80
|
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:
|
|
@@ -536,6 +536,99 @@ class NfcManager extends ReactContextBaseJavaModule implements ActivityEventList
|
|
|
536
536
|
}
|
|
537
537
|
}
|
|
538
538
|
|
|
539
|
+
@ReactMethod
|
|
540
|
+
public void mifareClassicIncrementBlock(int blockIndex, int value, Callback callback) {
|
|
541
|
+
synchronized(this) {
|
|
542
|
+
if (techRequest != null) {
|
|
543
|
+
try {
|
|
544
|
+
MifareClassic mifareTag = (MifareClassic) techRequest.getTechHandle();
|
|
545
|
+
if (mifareTag == null || mifareTag.getType() == MifareClassic.TYPE_UNKNOWN) {
|
|
546
|
+
// Not a mifare card, fail
|
|
547
|
+
callback.invoke("mifareClassicIncrementBlock fail: TYPE_UNKNOWN");
|
|
548
|
+
return;
|
|
549
|
+
} else if (blockIndex >= mifareTag.getBlockCount()) {
|
|
550
|
+
// Check if in range
|
|
551
|
+
String msg = String.format("mifareClassicIncrementBlock fail: invalid block %d (max %d)", blockIndex, mifareTag.getBlockCount());
|
|
552
|
+
callback.invoke(msg);
|
|
553
|
+
return;
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
mifareTag.increment(blockIndex, value);
|
|
557
|
+
|
|
558
|
+
callback.invoke(null, true);
|
|
559
|
+
} catch (TagLostException ex) {
|
|
560
|
+
callback.invoke("mifareClassicIncrementBlock fail: TAG_LOST");
|
|
561
|
+
} catch (Exception ex) {
|
|
562
|
+
callback.invoke("mifareClassicIncrementBlock fail: " + ex.toString());
|
|
563
|
+
}
|
|
564
|
+
} else {
|
|
565
|
+
callback.invoke(ERR_NO_TECH_REQ);
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
@ReactMethod
|
|
571
|
+
public void mifareClassicDecrementBlock(int blockIndex, int value, Callback callback) {
|
|
572
|
+
synchronized(this) {
|
|
573
|
+
if (techRequest != null) {
|
|
574
|
+
try {
|
|
575
|
+
MifareClassic mifareTag = (MifareClassic) techRequest.getTechHandle();
|
|
576
|
+
if (mifareTag == null || mifareTag.getType() == MifareClassic.TYPE_UNKNOWN) {
|
|
577
|
+
// Not a mifare card, fail
|
|
578
|
+
callback.invoke("mifareClassicDecrementBlock fail: TYPE_UNKNOWN");
|
|
579
|
+
return;
|
|
580
|
+
} else if (blockIndex >= mifareTag.getBlockCount()) {
|
|
581
|
+
// Check if in range
|
|
582
|
+
String msg = String.format("mifareClassicDecrementBlock fail: invalid block %d (max %d)", blockIndex, mifareTag.getBlockCount());
|
|
583
|
+
callback.invoke(msg);
|
|
584
|
+
return;
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
mifareTag.decrement(blockIndex, value);
|
|
588
|
+
|
|
589
|
+
callback.invoke(null, true);
|
|
590
|
+
} catch (TagLostException ex) {
|
|
591
|
+
callback.invoke("mifareClassicDecrementBlock fail: TAG_LOST");
|
|
592
|
+
} catch (Exception ex) {
|
|
593
|
+
callback.invoke("mifareClassicDecrementBlock fail: " + ex.toString());
|
|
594
|
+
}
|
|
595
|
+
} else {
|
|
596
|
+
callback.invoke(ERR_NO_TECH_REQ);
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
@ReactMethod
|
|
602
|
+
public void mifareClassicTransferBlock(int blockIndex, Callback callback) {
|
|
603
|
+
synchronized(this) {
|
|
604
|
+
if (techRequest != null) {
|
|
605
|
+
try {
|
|
606
|
+
MifareClassic mifareTag = (MifareClassic) techRequest.getTechHandle();
|
|
607
|
+
if (mifareTag == null || mifareTag.getType() == MifareClassic.TYPE_UNKNOWN) {
|
|
608
|
+
// Not a mifare card, fail
|
|
609
|
+
callback.invoke("mifareClassicTransferBlock fail: TYPE_UNKNOWN");
|
|
610
|
+
return;
|
|
611
|
+
} else if (blockIndex >= mifareTag.getBlockCount()) {
|
|
612
|
+
// Check if in range
|
|
613
|
+
String msg = String.format("mifareClassicTransferBlock fail: invalid block %d (max %d)", blockIndex, mifareTag.getBlockCount());
|
|
614
|
+
callback.invoke(msg);
|
|
615
|
+
return;
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
mifareTag.transfer(blockIndex);
|
|
619
|
+
|
|
620
|
+
callback.invoke(null, true);
|
|
621
|
+
} catch (TagLostException ex) {
|
|
622
|
+
callback.invoke("mifareClassicTransferBlock fail: TAG_LOST");
|
|
623
|
+
} catch (Exception ex) {
|
|
624
|
+
callback.invoke("mifareClassicTransferBlock fail: " + ex.toString());
|
|
625
|
+
}
|
|
626
|
+
} else {
|
|
627
|
+
callback.invoke(ERR_NO_TECH_REQ);
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
|
|
539
632
|
@ReactMethod
|
|
540
633
|
public void mifareUltralightReadPages(int pageOffset, Callback callback) {
|
|
541
634
|
synchronized(this) {
|
|
@@ -941,8 +1034,12 @@ class NfcManager extends ReactContextBaseJavaModule implements ActivityEventList
|
|
|
941
1034
|
return;
|
|
942
1035
|
}
|
|
943
1036
|
|
|
944
|
-
|
|
945
|
-
|
|
1037
|
+
try {
|
|
1038
|
+
currentActivity.startActivity(new Intent(Settings.ACTION_NFC_SETTINGS));
|
|
1039
|
+
callback.invoke(null, true);
|
|
1040
|
+
} catch (Exception ex) {
|
|
1041
|
+
callback.invoke(null, false);
|
|
1042
|
+
}
|
|
946
1043
|
}
|
|
947
1044
|
|
|
948
1045
|
@ReactMethod
|
package/index.d.ts
CHANGED
|
@@ -123,11 +123,26 @@ declare module 'react-native-nfc-manager' {
|
|
|
123
123
|
block: ArrayLike<number>,
|
|
124
124
|
simpliArr: any[],
|
|
125
125
|
) => Promise<void>;
|
|
126
|
+
mifareClassicIncrementBlock: (
|
|
127
|
+
block: ArrayLike<number>,
|
|
128
|
+
data: number,
|
|
129
|
+
) => Promise<void>;
|
|
130
|
+
mifareClassicDecrementBlock: (
|
|
131
|
+
block: ArrayLike<number>,
|
|
132
|
+
data: number,
|
|
133
|
+
) => Promise<void>;
|
|
134
|
+
mifareClassicTransferBlock: (
|
|
135
|
+
block: ArrayLike<number>,
|
|
136
|
+
) => Promise<void>;
|
|
126
137
|
mifareClassicGetSectorCount: () => Promise<number>;
|
|
127
138
|
mifareClassicAuthenticateA: (
|
|
128
139
|
sector: number,
|
|
129
140
|
keys: number[],
|
|
130
141
|
) => Promise<void>;
|
|
142
|
+
mifareClassicAuthenticateB: (
|
|
143
|
+
sector: number,
|
|
144
|
+
keys: number[],
|
|
145
|
+
) => Promise<void>;
|
|
131
146
|
}
|
|
132
147
|
|
|
133
148
|
interface MifareUltralightHandlerAndroid {
|
|
@@ -256,7 +271,7 @@ declare module 'react-native-nfc-manager' {
|
|
|
256
271
|
/**
|
|
257
272
|
* Android only
|
|
258
273
|
*/
|
|
259
|
-
goToNfcSetting(): Promise<
|
|
274
|
+
goToNfcSetting(): Promise<boolean>;
|
|
260
275
|
getLaunchTagEvent(): Promise<TagEvent | null>;
|
|
261
276
|
transceive(bytes: number[]): Promise<number[]>;
|
|
262
277
|
getMaxTransceiveLength(): Promise<number>;
|
package/ios/NfcManager.m
CHANGED
|
@@ -286,8 +286,12 @@ RCT_EXPORT_METHOD(requestTechnology: (NSArray *)techs options: (NSDictionary *)o
|
|
|
286
286
|
{
|
|
287
287
|
if (@available(iOS 13.0, *)) {
|
|
288
288
|
if (tagSession == nil && session == nil) {
|
|
289
|
+
NFCPollingOption pollFlags = NFCPollingISO14443 | NFCPollingISO15693;
|
|
290
|
+
if ([techs containsObject:@"felica"]) {
|
|
291
|
+
pollFlags |= NFCPollingISO18092;
|
|
292
|
+
}
|
|
289
293
|
tagSession = [[NFCTagReaderSession alloc]
|
|
290
|
-
|
|
294
|
+
initWithPollingOption:pollFlags delegate:self queue:dispatch_get_main_queue()];
|
|
291
295
|
tagSession.alertMessage = [options objectForKey:@"alertMessage"];
|
|
292
296
|
[tagSession beginSession];
|
|
293
297
|
techRequestTypes = techs;
|
package/package.json
CHANGED
|
@@ -67,6 +67,48 @@ class MifareClassicHandlerAndroid {
|
|
|
67
67
|
callNative('mifareClassicWriteBlock', [block, data]),
|
|
68
68
|
);
|
|
69
69
|
}
|
|
70
|
+
|
|
71
|
+
async mifareClassicIncrementBlock(block, value) {
|
|
72
|
+
if (
|
|
73
|
+
!value ||
|
|
74
|
+
Number.isNaN(value)) {
|
|
75
|
+
throw new Error(
|
|
76
|
+
`value should be a number`,
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return handleNativeException(
|
|
81
|
+
callNative('mifareClassicIncrementBlock', [block, value]),
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
async mifareClassicDecrementBlock(block, value) {
|
|
86
|
+
if (
|
|
87
|
+
!value ||
|
|
88
|
+
Number.isNaN(value)) {
|
|
89
|
+
throw new Error(
|
|
90
|
+
`value should be a number`,
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return handleNativeException(
|
|
95
|
+
callNative('mifareClassicDecrementBlock', [block, value]),
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
async mifareClassicTransferBlock(block) {
|
|
99
|
+
if (
|
|
100
|
+
!block ||
|
|
101
|
+
Number.isNaN(block)) {
|
|
102
|
+
throw new Error(
|
|
103
|
+
`block should be a number`,
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return handleNativeException(
|
|
108
|
+
callNative('mifareClassicTransferBlock', [block]),
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
|
|
70
112
|
}
|
|
71
113
|
|
|
72
114
|
export {MifareClassicHandlerAndroid};
|