react-native-nfc-manager 3.13.0 → 3.13.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/android/src/main/java/community/revteltech/nfc/MifareUtil.java +3 -3
- package/android/src/main/java/community/revteltech/nfc/NfcManager.java +16 -16
- package/android/src/main/java/community/revteltech/nfc/Util.java +9 -9
- package/ios/NfcManager.h +5 -0
- package/ios/NfcManager.m +76 -129
- package/ios/Util.m +55 -0
- package/ndef-lib/index.js +1 -1
- package/package.json +1 -1
|
@@ -49,7 +49,7 @@ class MifareUtil {
|
|
|
49
49
|
// able of reading/writing MIFARE Classic tags. I don't know why...
|
|
50
50
|
// https://github.com/ikarus23/MifareClassicTool/issues/152
|
|
51
51
|
boolean isLenovoP2 = Build.MANUFACTURER.equals("LENOVO")
|
|
52
|
-
|
|
52
|
+
&& Build.MODEL.equals("Lenovo P2a42");
|
|
53
53
|
File device = new File("/dev/bcm2079x-i2c");
|
|
54
54
|
if (!isLenovoP2 && device.exists()) {
|
|
55
55
|
return false;
|
|
@@ -70,8 +70,8 @@ class MifareUtil {
|
|
|
70
70
|
File[] libs = libsFolder.listFiles();
|
|
71
71
|
for (File lib : libs) {
|
|
72
72
|
if (lib.isFile()
|
|
73
|
-
|
|
74
|
-
|
|
73
|
+
&& lib.getName().startsWith("libnfc")
|
|
74
|
+
&& lib.getName().contains("brcm")
|
|
75
75
|
// Add here other non NXP NFC libraries.
|
|
76
76
|
) {
|
|
77
77
|
return false;
|
|
@@ -646,27 +646,27 @@ class NfcManager extends ReactContextBaseJavaModule implements ActivityEventList
|
|
|
646
646
|
@ReactMethod
|
|
647
647
|
public void connect(ReadableArray techs, Callback callback){
|
|
648
648
|
synchronized(this) {
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
649
|
+
try {
|
|
650
|
+
techRequest = new TagTechnologyRequest(techs.toArrayList(), callback);
|
|
651
|
+
techRequest.connect(this.tag);
|
|
652
|
+
callback.invoke(null, null);
|
|
653
|
+
return;
|
|
654
|
+
} catch (Exception ex) {
|
|
655
|
+
callback.invoke(ex.toString());
|
|
656
|
+
}
|
|
657
657
|
}
|
|
658
658
|
}
|
|
659
659
|
|
|
660
660
|
@ReactMethod
|
|
661
661
|
public void close(Callback callback){
|
|
662
662
|
synchronized(this) {
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
663
|
+
try {
|
|
664
|
+
techRequest.close();
|
|
665
|
+
callback.invoke(null, null);
|
|
666
|
+
return;
|
|
667
|
+
} catch (Exception ex) {
|
|
668
|
+
callback.invoke(ex.toString());
|
|
669
|
+
}
|
|
670
670
|
}
|
|
671
671
|
}
|
|
672
672
|
|
|
@@ -1107,7 +1107,7 @@ class NfcManager extends ReactContextBaseJavaModule implements ActivityEventList
|
|
|
1107
1107
|
|
|
1108
1108
|
int flag = 0;
|
|
1109
1109
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
|
1110
|
-
|
|
1110
|
+
flag = PendingIntent.FLAG_MUTABLE;
|
|
1111
1111
|
}
|
|
1112
1112
|
return PendingIntent.getActivity(activity, 0, intent, flag);
|
|
1113
1113
|
}
|
|
@@ -39,9 +39,9 @@ public class Util {
|
|
|
39
39
|
// mTag.getTagService(); of the Ndef object sometimes returns null
|
|
40
40
|
// see http://issues.mroland.at/index.php?do=details&task_id=47
|
|
41
41
|
try {
|
|
42
|
-
|
|
42
|
+
json.put("canMakeReadOnly", ndef.canMakeReadOnly());
|
|
43
43
|
} catch (NullPointerException e) {
|
|
44
|
-
|
|
44
|
+
json.put("canMakeReadOnly", JSONObject.NULL);
|
|
45
45
|
}
|
|
46
46
|
} catch (JSONException e) {
|
|
47
47
|
Log.e(TAG, "Failed to convert ndef into json: " + ndef.toString(), e);
|
|
@@ -104,16 +104,16 @@ public class Util {
|
|
|
104
104
|
}
|
|
105
105
|
|
|
106
106
|
public static String bytesToHex(byte[] bytes) {
|
|
107
|
-
|
|
107
|
+
char[] hexChars = new char[bytes.length * 2];
|
|
108
108
|
|
|
109
|
-
|
|
110
|
-
|
|
109
|
+
for ( int j = 0; j < bytes.length; j++ ) {
|
|
110
|
+
int v = bytes[j] & 0xFF;
|
|
111
111
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
112
|
+
hexChars[j * 2] = hexArray[v >>> 4];
|
|
113
|
+
hexChars[j * 2 + 1] = hexArray[v & 0x0F];
|
|
114
|
+
}
|
|
115
115
|
|
|
116
|
-
|
|
116
|
+
return new String(hexChars);
|
|
117
117
|
}
|
|
118
118
|
|
|
119
119
|
static byte[] jsonToByteArray(JSONArray json) throws JSONException {
|
package/ios/NfcManager.h
CHANGED
|
@@ -30,3 +30,8 @@
|
|
|
30
30
|
#endif
|
|
31
31
|
|
|
32
32
|
@end
|
|
33
|
+
|
|
34
|
+
extern NSString* _Nonnull getHexString(NSData * _Nonnull);
|
|
35
|
+
extern NSString* _Nonnull getErrorMessage(NSError * _Nonnull);
|
|
36
|
+
extern NSData * _Nonnull arrayToData(NSArray * _Nonnull);
|
|
37
|
+
extern NSArray * _Nonnull dataToArray(NSData * _Nonnull);
|
package/ios/NfcManager.m
CHANGED
|
@@ -4,29 +4,6 @@
|
|
|
4
4
|
#import "React/RCTEventDispatcher.h"
|
|
5
5
|
#import "React/RCTLog.h"
|
|
6
6
|
|
|
7
|
-
NSString* getHexString(NSData *data) {
|
|
8
|
-
NSUInteger capacity = data.length * 2;
|
|
9
|
-
NSMutableString *sbuf = [NSMutableString stringWithCapacity:capacity];
|
|
10
|
-
const unsigned char *buf = data.bytes;
|
|
11
|
-
NSInteger i;
|
|
12
|
-
for (i=0; i<data.length; ++i) {
|
|
13
|
-
[sbuf appendFormat:@"%02lX", (unsigned long)buf[i]];
|
|
14
|
-
}
|
|
15
|
-
return sbuf;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
NSString* getErrorMessage(NSError *error) {
|
|
19
|
-
NSDictionary *userInfo = [error userInfo];
|
|
20
|
-
NSError *underlyingError = [userInfo objectForKey:NSUnderlyingErrorKey];
|
|
21
|
-
if (underlyingError != nil) {
|
|
22
|
-
return [NSString stringWithFormat:@"%@:%ld,%@:%ld",
|
|
23
|
-
[error domain], (long)[error code],
|
|
24
|
-
[underlyingError domain], (long)[underlyingError code]];
|
|
25
|
-
}
|
|
26
|
-
return [NSString stringWithFormat:@"%@:%ld",
|
|
27
|
-
[error domain], (long)[error code]];
|
|
28
|
-
}
|
|
29
|
-
|
|
30
7
|
@implementation NfcManager {
|
|
31
8
|
NSDictionary *nfcTechTypes;
|
|
32
9
|
NSArray *techRequestTypes;
|
|
@@ -37,7 +14,6 @@ RCT_EXPORT_MODULE()
|
|
|
37
14
|
|
|
38
15
|
@synthesize session;
|
|
39
16
|
@synthesize tagSession;
|
|
40
|
-
@synthesize bridge = _bridge;
|
|
41
17
|
|
|
42
18
|
static NSString *const kBgNfcTagNotification = @"RNBgNfcTagNotification";
|
|
43
19
|
NSArray * bgNdefRecords = nil;
|
|
@@ -112,38 +88,12 @@ continueUserActivity:(NSUserActivity *)userActivity
|
|
|
112
88
|
];
|
|
113
89
|
}
|
|
114
90
|
|
|
115
|
-
- (NSData *)arrayToData: (NSArray *) array
|
|
116
|
-
{
|
|
117
|
-
Byte bytes[[array count]];
|
|
118
|
-
for (int i = 0; i < [array count]; i++) {
|
|
119
|
-
bytes[i] = [[array objectAtIndex:i] integerValue];
|
|
120
|
-
}
|
|
121
|
-
NSData *payload = [[NSData alloc] initWithBytes:bytes length:[array count]];
|
|
122
|
-
return payload;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
+ (NSArray *)dataToArray:(NSData *)data
|
|
126
|
-
{
|
|
127
|
-
const unsigned char *dataBuffer = data ? (const unsigned char *)[data bytes] : NULL;
|
|
128
|
-
|
|
129
|
-
if (!dataBuffer)
|
|
130
|
-
return @[];
|
|
131
|
-
|
|
132
|
-
NSUInteger dataLength = [data length];
|
|
133
|
-
NSMutableArray *array = [NSMutableArray arrayWithCapacity:dataLength];
|
|
134
|
-
|
|
135
|
-
for (int i = 0; i < dataLength; ++i)
|
|
136
|
-
[array addObject:[NSNumber numberWithInteger:dataBuffer[i]]];
|
|
137
|
-
|
|
138
|
-
return array;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
91
|
+ (NSDictionary*)convertNdefRecord:(NFCNDEFPayload *) record
|
|
142
92
|
{
|
|
143
93
|
return @{
|
|
144
|
-
@"id":
|
|
145
|
-
@"payload":
|
|
146
|
-
@"type":
|
|
94
|
+
@"id": dataToArray([record identifier]),
|
|
95
|
+
@"payload": dataToArray([record payload]),
|
|
96
|
+
@"type": dataToArray([record type]),
|
|
147
97
|
@"tnf": [NSNumber numberWithInt:[record typeNameFormat]]
|
|
148
98
|
};
|
|
149
99
|
}
|
|
@@ -179,13 +129,13 @@ continueUserActivity:(NSUserActivity *)userActivity
|
|
|
179
129
|
id<NFCISO7816Tag> iso7816Tag = [tag asNFCISO7816Tag];
|
|
180
130
|
[tagInfo setObject:getHexString(iso7816Tag.identifier) forKey:@"id"];
|
|
181
131
|
[tagInfo setObject:iso7816Tag.initialSelectedAID forKey:@"initialSelectedAID"];
|
|
182
|
-
[tagInfo setObject:
|
|
183
|
-
[tagInfo setObject:
|
|
132
|
+
[tagInfo setObject:dataToArray(iso7816Tag.historicalBytes) forKey:@"historicalBytes"];
|
|
133
|
+
[tagInfo setObject:dataToArray(iso7816Tag.applicationData) forKey:@"applicationData"];
|
|
184
134
|
} else if (tag.type == NFCTagTypeISO15693) {
|
|
185
135
|
id<NFCISO15693Tag> iso15693Tag = [tag asNFCISO15693Tag];
|
|
186
136
|
[tagInfo setObject:getHexString(iso15693Tag.identifier) forKey:@"id"];
|
|
187
137
|
[tagInfo setObject:[NSNumber numberWithUnsignedInteger:iso15693Tag.icManufacturerCode] forKey:@"icManufacturerCode"];
|
|
188
|
-
[tagInfo setObject:
|
|
138
|
+
[tagInfo setObject:dataToArray(iso15693Tag.icSerialNumber) forKey:@"icSerialNumber"];
|
|
189
139
|
} else if (tag.type == NFCTagTypeFeliCa) {
|
|
190
140
|
id<NFCFeliCaTag> felicaTag = [tag asNFCFeliCaTag];
|
|
191
141
|
[tagInfo setObject:getHexString(felicaTag.currentIDm) forKey:@"idm"];
|
|
@@ -196,18 +146,17 @@ continueUserActivity:(NSUserActivity *)userActivity
|
|
|
196
146
|
return tagInfo;
|
|
197
147
|
}
|
|
198
148
|
|
|
199
|
-
- (id<NFCNDEFTag>)getNDEFTagHandle:(id<NFCTag>)tag
|
|
149
|
+
- (id<NFCNDEFTag>)getNDEFTagHandle:(id<NFCTag>)tag
|
|
150
|
+
API_AVAILABLE(ios(13.0)) {
|
|
200
151
|
// all following types inherite from NFCNDEFTag
|
|
201
|
-
if (
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
return [tag asNFCFeliCaTag];
|
|
210
|
-
}
|
|
152
|
+
if (tag.type == NFCTagTypeMiFare) {
|
|
153
|
+
return [tag asNFCMiFareTag];
|
|
154
|
+
} else if (tag.type == NFCTagTypeISO7816Compatible) {
|
|
155
|
+
return [tag asNFCISO7816Tag];
|
|
156
|
+
} else if (tag.type == NFCTagTypeISO15693) {
|
|
157
|
+
return [tag asNFCISO15693Tag];
|
|
158
|
+
} else if (tag.type == NFCTagTypeFeliCa) {
|
|
159
|
+
return [tag asNFCFeliCaTag];
|
|
211
160
|
}
|
|
212
161
|
|
|
213
162
|
return nil;
|
|
@@ -235,31 +184,29 @@ continueUserActivity:(NSUserActivity *)userActivity
|
|
|
235
184
|
}
|
|
236
185
|
|
|
237
186
|
- (void)tagReaderSession:(NFCTagReaderSession *)session didDetectTags:(NSArray<__kindof id<NFCTag>> *)tags
|
|
238
|
-
{
|
|
187
|
+
API_AVAILABLE(ios(13.0)) {
|
|
239
188
|
NSLog(@"NFCTag didDetectTags");
|
|
240
|
-
if (
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
return;
|
|
262
|
-
}
|
|
189
|
+
if (techRequestCallback != nil) {
|
|
190
|
+
for (id<NFCTag> tag in tags) {
|
|
191
|
+
NSString * tagType = [self getRNTechName:tag];
|
|
192
|
+
|
|
193
|
+
for (NSString* requestType in techRequestTypes) {
|
|
194
|
+
// here we treat Ndef is a special case, because all specific tech types
|
|
195
|
+
// inherites from NFCNDEFTag, so we simply allow it to connect
|
|
196
|
+
if ([tagType isEqualToString:requestType] || [requestType isEqualToString:@"Ndef"]) {
|
|
197
|
+
RCTResponseSenderBlock pendingCallback = techRequestCallback;
|
|
198
|
+
techRequestCallback = nil;
|
|
199
|
+
|
|
200
|
+
[tagSession connectToTag:tag
|
|
201
|
+
completionHandler:^(NSError *error) {
|
|
202
|
+
if (error != nil) {
|
|
203
|
+
pendingCallback(@[getErrorMessage(error)]);
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
pendingCallback(@[[NSNull null], requestType]);
|
|
208
|
+
}];
|
|
209
|
+
return;
|
|
263
210
|
}
|
|
264
211
|
}
|
|
265
212
|
}
|
|
@@ -267,7 +214,7 @@ continueUserActivity:(NSUserActivity *)userActivity
|
|
|
267
214
|
}
|
|
268
215
|
|
|
269
216
|
- (void)tagReaderSession:(NFCTagReaderSession *)session didInvalidateWithError:(NSError *)error
|
|
270
|
-
{
|
|
217
|
+
API_AVAILABLE(ios(13.0)) {
|
|
271
218
|
NSLog(@"NFCTag didInvalidateWithError");
|
|
272
219
|
if (techRequestCallback) {
|
|
273
220
|
techRequestCallback(@[getErrorMessage(error)]);
|
|
@@ -280,7 +227,7 @@ continueUserActivity:(NSUserActivity *)userActivity
|
|
|
280
227
|
}
|
|
281
228
|
|
|
282
229
|
- (void)tagReaderSessionDidBecomeActive:(NFCTagReaderSession *)session
|
|
283
|
-
{
|
|
230
|
+
API_AVAILABLE(ios(13.0)) {
|
|
284
231
|
NSLog(@"NFCTag didBecomeActive");
|
|
285
232
|
}
|
|
286
233
|
|
|
@@ -499,7 +446,7 @@ RCT_EXPORT_METHOD(writeNdefMessage:(NSArray*)bytes callback:(nonnull RCTResponse
|
|
|
499
446
|
}
|
|
500
447
|
|
|
501
448
|
if (ndefTag) {
|
|
502
|
-
NSData *data =
|
|
449
|
+
NSData *data = arrayToData(bytes);
|
|
503
450
|
NFCNDEFMessage *ndefMsg = [NFCNDEFMessage ndefMessageWithData:data];
|
|
504
451
|
if (!ndefMsg) {
|
|
505
452
|
callback(@[@"invalid ndef msg"]);
|
|
@@ -568,8 +515,8 @@ RCT_EXPORT_METHOD(queryNDEFStatus:(nonnull RCTResponseSenderBlock)callback)
|
|
|
568
515
|
} else {
|
|
569
516
|
callback(@[[NSNull null],
|
|
570
517
|
@{
|
|
571
|
-
@"status": [[NSNumber alloc] initWithInt:status],
|
|
572
|
-
@"capacity": [[NSNumber alloc] initWithInt:capacity]
|
|
518
|
+
@"status": [[NSNumber alloc] initWithInt:(int)status],
|
|
519
|
+
@"capacity": [[NSNumber alloc] initWithInt:(int)capacity]
|
|
573
520
|
}
|
|
574
521
|
]);
|
|
575
522
|
}
|
|
@@ -591,7 +538,7 @@ RCT_EXPORT_METHOD(sendMifareCommand:(NSArray *)bytes callback: (nonnull RCTRespo
|
|
|
591
538
|
if (tagSession != nil) {
|
|
592
539
|
if (tagSession.connectedTag) {
|
|
593
540
|
id<NFCMiFareTag> mifareTag = [tagSession.connectedTag asNFCMiFareTag];
|
|
594
|
-
NSData *data =
|
|
541
|
+
NSData *data = arrayToData(bytes);
|
|
595
542
|
NSLog(@"input bytes: %@", getHexString(data));
|
|
596
543
|
if (mifareTag) {
|
|
597
544
|
[mifareTag sendMiFareCommand:data
|
|
@@ -599,7 +546,7 @@ RCT_EXPORT_METHOD(sendMifareCommand:(NSArray *)bytes callback: (nonnull RCTRespo
|
|
|
599
546
|
if (error) {
|
|
600
547
|
callback(@[getErrorMessage(error), [NSNull null]]);
|
|
601
548
|
} else {
|
|
602
|
-
callback(@[[NSNull null],
|
|
549
|
+
callback(@[[NSNull null], dataToArray(response)]);
|
|
603
550
|
}
|
|
604
551
|
}];
|
|
605
552
|
return;
|
|
@@ -622,7 +569,7 @@ RCT_EXPORT_METHOD(sendFelicaCommand:(NSArray *)bytes callback: (nonnull RCTRespo
|
|
|
622
569
|
if (tagSession != nil) {
|
|
623
570
|
if (tagSession.connectedTag) {
|
|
624
571
|
id<NFCFeliCaTag> felicaTag = [tagSession.connectedTag asNFCFeliCaTag];
|
|
625
|
-
NSData *data =
|
|
572
|
+
NSData *data = arrayToData(bytes);
|
|
626
573
|
NSLog(@"input bytes: %@", getHexString(data));
|
|
627
574
|
if (felicaTag) {
|
|
628
575
|
[felicaTag sendFeliCaCommandPacket:data
|
|
@@ -630,7 +577,7 @@ RCT_EXPORT_METHOD(sendFelicaCommand:(NSArray *)bytes callback: (nonnull RCTRespo
|
|
|
630
577
|
if (error) {
|
|
631
578
|
callback(@[getErrorMessage(error), [NSNull null]]);
|
|
632
579
|
} else {
|
|
633
|
-
callback(@[[NSNull null],
|
|
580
|
+
callback(@[[NSNull null], dataToArray(response)]);
|
|
634
581
|
}
|
|
635
582
|
}];
|
|
636
583
|
return;
|
|
@@ -653,14 +600,14 @@ RCT_EXPORT_METHOD(sendCommandAPDUBytes:(NSArray *)bytes callback: (nonnull RCTRe
|
|
|
653
600
|
if (tagSession != nil) {
|
|
654
601
|
if (tagSession.connectedTag) {
|
|
655
602
|
id<NFCISO7816Tag> iso7816Tag = [tagSession.connectedTag asNFCISO7816Tag];
|
|
656
|
-
NSData *data =
|
|
603
|
+
NSData *data = arrayToData(bytes);
|
|
657
604
|
NFCISO7816APDU *apdu = [[NFCISO7816APDU alloc] initWithData:data];
|
|
658
605
|
if (iso7816Tag) {
|
|
659
606
|
[iso7816Tag sendCommandAPDU:apdu completionHandler:^(NSData* response, uint8_t sw1, uint8_t sw2, NSError* error) {
|
|
660
607
|
if (error) {
|
|
661
608
|
callback(@[getErrorMessage(error), [NSNull null]]);
|
|
662
609
|
} else {
|
|
663
|
-
callback(@[[NSNull null],
|
|
610
|
+
callback(@[[NSNull null], dataToArray(response), [NSNumber numberWithInt:sw1], [NSNumber numberWithInt:sw2]]);
|
|
664
611
|
}
|
|
665
612
|
}];
|
|
666
613
|
return;
|
|
@@ -688,7 +635,7 @@ RCT_EXPORT_METHOD(sendCommandAPDU:(NSDictionary *)apduData callback: (nonnull RC
|
|
|
688
635
|
NSNumber *p1 = [apduData objectForKey:@"p1"];
|
|
689
636
|
NSNumber *p2 = [apduData objectForKey:@"p2"];
|
|
690
637
|
NSArray *dataArray = [apduData objectForKey:@"data"];
|
|
691
|
-
NSData *data =
|
|
638
|
+
NSData *data = arrayToData(dataArray);
|
|
692
639
|
NSNumber *le = [apduData objectForKey:@"le"];
|
|
693
640
|
|
|
694
641
|
/*
|
|
@@ -701,7 +648,7 @@ RCT_EXPORT_METHOD(sendCommandAPDU:(NSDictionary *)apduData callback: (nonnull RC
|
|
|
701
648
|
if (error) {
|
|
702
649
|
callback(@[getErrorMessage(error), [NSNull null]]);
|
|
703
650
|
} else {
|
|
704
|
-
callback(@[[NSNull null],
|
|
651
|
+
callback(@[[NSNull null], dataToArray(response), [NSNumber numberWithInt:sw1], [NSNumber numberWithInt:sw2]]);
|
|
705
652
|
}
|
|
706
653
|
}];
|
|
707
654
|
return;
|
|
@@ -758,7 +705,7 @@ RCT_EXPORT_METHOD(isTagSessionAvailable:(nonnull RCTResponseSenderBlock)callback
|
|
|
758
705
|
// ---------------------------
|
|
759
706
|
RCT_EXPORT_METHOD(iso15693_getSystemInfo:(nonnull NSNumber *)flags callback:(nonnull RCTResponseSenderBlock)callback)
|
|
760
707
|
{
|
|
761
|
-
if (@available(iOS
|
|
708
|
+
if (@available(iOS 14.0, *)) {
|
|
762
709
|
if (!tagSession || !tagSession.connectedTag) {
|
|
763
710
|
callback(@[@"Not connected", [NSNull null]]);
|
|
764
711
|
return;
|
|
@@ -794,7 +741,7 @@ RCT_EXPORT_METHOD(iso15693_getSystemInfo:(nonnull NSNumber *)flags callback:(non
|
|
|
794
741
|
|
|
795
742
|
RCT_EXPORT_METHOD(iso15693_readSingleBlock:(NSDictionary *)options callback:(nonnull RCTResponseSenderBlock)callback)
|
|
796
743
|
{
|
|
797
|
-
if (@available(iOS
|
|
744
|
+
if (@available(iOS 14.0, *)) {
|
|
798
745
|
if (!tagSession || !tagSession.connectedTag) {
|
|
799
746
|
callback(@[@"Not connected", [NSNull null]]);
|
|
800
747
|
return;
|
|
@@ -817,7 +764,7 @@ RCT_EXPORT_METHOD(iso15693_readSingleBlock:(NSDictionary *)options callback:(non
|
|
|
817
764
|
return;
|
|
818
765
|
}
|
|
819
766
|
|
|
820
|
-
callback(@[[NSNull null],
|
|
767
|
+
callback(@[[NSNull null], dataToArray(resp)]);
|
|
821
768
|
}];
|
|
822
769
|
} else {
|
|
823
770
|
callback(@[@"Not support in this device", [NSNull null]]);
|
|
@@ -826,7 +773,7 @@ RCT_EXPORT_METHOD(iso15693_readSingleBlock:(NSDictionary *)options callback:(non
|
|
|
826
773
|
|
|
827
774
|
RCT_EXPORT_METHOD(iso15693_readMultipleBlocks:(NSDictionary *)options callback:(nonnull RCTResponseSenderBlock)callback)
|
|
828
775
|
{
|
|
829
|
-
if (@available(iOS
|
|
776
|
+
if (@available(iOS 14.0, *)) {
|
|
830
777
|
if (!tagSession || !tagSession.connectedTag) {
|
|
831
778
|
callback(@[@"Not connected", [NSNull null]]);
|
|
832
779
|
return;
|
|
@@ -853,7 +800,7 @@ RCT_EXPORT_METHOD(iso15693_readMultipleBlocks:(NSDictionary *)options callback:(
|
|
|
853
800
|
}
|
|
854
801
|
NSMutableArray *blocks = [NSMutableArray arrayWithCapacity:[dataBlocks count]];
|
|
855
802
|
[dataBlocks enumerateObjectsUsingBlock:^(NSData *blockData, NSUInteger idx, BOOL *stop) {
|
|
856
|
-
[blocks addObject:
|
|
803
|
+
[blocks addObject:dataToArray(blockData)];
|
|
857
804
|
}];
|
|
858
805
|
callback(@[[NSNull null], blocks]);
|
|
859
806
|
}];
|
|
@@ -864,7 +811,7 @@ RCT_EXPORT_METHOD(iso15693_readMultipleBlocks:(NSDictionary *)options callback:(
|
|
|
864
811
|
|
|
865
812
|
RCT_EXPORT_METHOD(iso15693_writeSingleBlock:(NSDictionary *)options callback:(nonnull RCTResponseSenderBlock)callback)
|
|
866
813
|
{
|
|
867
|
-
if (@available(iOS
|
|
814
|
+
if (@available(iOS 14.0, *)) {
|
|
868
815
|
if (!tagSession || !tagSession.connectedTag) {
|
|
869
816
|
callback(@[@"Not connected", [NSNull null]]);
|
|
870
817
|
return;
|
|
@@ -878,7 +825,7 @@ RCT_EXPORT_METHOD(iso15693_writeSingleBlock:(NSDictionary *)options callback:(no
|
|
|
878
825
|
|
|
879
826
|
RequestFlag flags = [[options objectForKey:@"flags"] unsignedIntValue];
|
|
880
827
|
uint8_t blockNumber = [[options objectForKey:@"blockNumber"] unsignedIntValue];
|
|
881
|
-
NSData *dataBlock =
|
|
828
|
+
NSData *dataBlock = arrayToData([options mutableArrayValueForKey:@"dataBlock"]);
|
|
882
829
|
|
|
883
830
|
[tag writeSingleBlockWithRequestFlags:flags
|
|
884
831
|
blockNumber:blockNumber
|
|
@@ -898,7 +845,7 @@ RCT_EXPORT_METHOD(iso15693_writeSingleBlock:(NSDictionary *)options callback:(no
|
|
|
898
845
|
|
|
899
846
|
RCT_EXPORT_METHOD(iso15693_lockBlock:(NSDictionary *)options callback:(nonnull RCTResponseSenderBlock)callback)
|
|
900
847
|
{
|
|
901
|
-
if (@available(iOS
|
|
848
|
+
if (@available(iOS 14.0, *)) {
|
|
902
849
|
if (!tagSession || !tagSession.connectedTag) {
|
|
903
850
|
callback(@[@"Not connected", [NSNull null]]);
|
|
904
851
|
return;
|
|
@@ -930,7 +877,7 @@ RCT_EXPORT_METHOD(iso15693_lockBlock:(NSDictionary *)options callback:(nonnull R
|
|
|
930
877
|
|
|
931
878
|
RCT_EXPORT_METHOD(iso15693_writeAFI:(NSDictionary *)options callback:(nonnull RCTResponseSenderBlock)callback)
|
|
932
879
|
{
|
|
933
|
-
if (@available(iOS
|
|
880
|
+
if (@available(iOS 14.0, *)) {
|
|
934
881
|
if (!tagSession || !tagSession.connectedTag) {
|
|
935
882
|
callback(@[@"Not connected", [NSNull null]]);
|
|
936
883
|
return;
|
|
@@ -962,7 +909,7 @@ RCT_EXPORT_METHOD(iso15693_writeAFI:(NSDictionary *)options callback:(nonnull RC
|
|
|
962
909
|
|
|
963
910
|
RCT_EXPORT_METHOD(iso15693_lockAFI:(NSDictionary *)options callback:(nonnull RCTResponseSenderBlock)callback)
|
|
964
911
|
{
|
|
965
|
-
if (@available(iOS
|
|
912
|
+
if (@available(iOS 14.0, *)) {
|
|
966
913
|
if (!tagSession || !tagSession.connectedTag) {
|
|
967
914
|
callback(@[@"Not connected", [NSNull null]]);
|
|
968
915
|
return;
|
|
@@ -992,7 +939,7 @@ RCT_EXPORT_METHOD(iso15693_lockAFI:(NSDictionary *)options callback:(nonnull RCT
|
|
|
992
939
|
|
|
993
940
|
RCT_EXPORT_METHOD(iso15693_writeDSFID:(NSDictionary *)options callback:(nonnull RCTResponseSenderBlock)callback)
|
|
994
941
|
{
|
|
995
|
-
if (@available(iOS
|
|
942
|
+
if (@available(iOS 14.0, *)) {
|
|
996
943
|
if (!tagSession || !tagSession.connectedTag) {
|
|
997
944
|
callback(@[@"Not connected", [NSNull null]]);
|
|
998
945
|
return;
|
|
@@ -1024,7 +971,7 @@ RCT_EXPORT_METHOD(iso15693_writeDSFID:(NSDictionary *)options callback:(nonnull
|
|
|
1024
971
|
|
|
1025
972
|
RCT_EXPORT_METHOD(iso15693_lockDSFID:(NSDictionary *)options callback:(nonnull RCTResponseSenderBlock)callback)
|
|
1026
973
|
{
|
|
1027
|
-
if (@available(iOS
|
|
974
|
+
if (@available(iOS 14.0, *)) {
|
|
1028
975
|
if (!tagSession || !tagSession.connectedTag) {
|
|
1029
976
|
callback(@[@"Not connected", [NSNull null]]);
|
|
1030
977
|
return;
|
|
@@ -1055,7 +1002,7 @@ RCT_EXPORT_METHOD(iso15693_lockDSFID:(NSDictionary *)options callback:(nonnull R
|
|
|
1055
1002
|
|
|
1056
1003
|
RCT_EXPORT_METHOD(iso15693_resetToReady:(NSDictionary *)options callback:(nonnull RCTResponseSenderBlock)callback)
|
|
1057
1004
|
{
|
|
1058
|
-
if (@available(iOS
|
|
1005
|
+
if (@available(iOS 14.0, *)) {
|
|
1059
1006
|
if (!tagSession || !tagSession.connectedTag) {
|
|
1060
1007
|
callback(@[@"Not connected", [NSNull null]]);
|
|
1061
1008
|
return;
|
|
@@ -1085,7 +1032,7 @@ RCT_EXPORT_METHOD(iso15693_resetToReady:(NSDictionary *)options callback:(nonnul
|
|
|
1085
1032
|
|
|
1086
1033
|
RCT_EXPORT_METHOD(iso15693_select:(NSDictionary *)options callback:(nonnull RCTResponseSenderBlock)callback)
|
|
1087
1034
|
{
|
|
1088
|
-
if (@available(iOS
|
|
1035
|
+
if (@available(iOS 14.0, *)) {
|
|
1089
1036
|
if (!tagSession || !tagSession.connectedTag) {
|
|
1090
1037
|
callback(@[@"Not connected", [NSNull null]]);
|
|
1091
1038
|
return;
|
|
@@ -1115,7 +1062,7 @@ RCT_EXPORT_METHOD(iso15693_select:(NSDictionary *)options callback:(nonnull RCTR
|
|
|
1115
1062
|
|
|
1116
1063
|
RCT_EXPORT_METHOD(iso15693_stayQuiet:(nonnull RCTResponseSenderBlock)callback)
|
|
1117
1064
|
{
|
|
1118
|
-
if (@available(iOS
|
|
1065
|
+
if (@available(iOS 14.0, *)) {
|
|
1119
1066
|
if (!tagSession || !tagSession.connectedTag) {
|
|
1120
1067
|
callback(@[@"Not connected", [NSNull null]]);
|
|
1121
1068
|
return;
|
|
@@ -1142,7 +1089,7 @@ RCT_EXPORT_METHOD(iso15693_stayQuiet:(nonnull RCTResponseSenderBlock)callback)
|
|
|
1142
1089
|
|
|
1143
1090
|
RCT_EXPORT_METHOD(iso15693_customCommand:(NSDictionary *)options callback:(nonnull RCTResponseSenderBlock)callback)
|
|
1144
1091
|
{
|
|
1145
|
-
if (@available(iOS
|
|
1092
|
+
if (@available(iOS 14.0, *)) {
|
|
1146
1093
|
if (!tagSession || !tagSession.connectedTag) {
|
|
1147
1094
|
callback(@[@"Not connected", [NSNull null]]);
|
|
1148
1095
|
return;
|
|
@@ -1156,7 +1103,7 @@ RCT_EXPORT_METHOD(iso15693_customCommand:(NSDictionary *)options callback:(nonnu
|
|
|
1156
1103
|
|
|
1157
1104
|
RequestFlag flags = [[options objectForKey:@"flags"] unsignedIntValue];
|
|
1158
1105
|
NSInteger customCommandCode = [[options objectForKey:@"customCommandCode"] integerValue];
|
|
1159
|
-
NSData *customRequestParameters =
|
|
1106
|
+
NSData *customRequestParameters = arrayToData([options mutableArrayValueForKey:@"customRequestParameters"]);
|
|
1160
1107
|
|
|
1161
1108
|
[tag customCommandWithRequestFlag:flags
|
|
1162
1109
|
customCommandCode: customCommandCode
|
|
@@ -1167,7 +1114,7 @@ RCT_EXPORT_METHOD(iso15693_customCommand:(NSDictionary *)options callback:(nonnu
|
|
|
1167
1114
|
return;
|
|
1168
1115
|
}
|
|
1169
1116
|
|
|
1170
|
-
callback(@[[NSNull null],
|
|
1117
|
+
callback(@[[NSNull null], dataToArray(resp)]);
|
|
1171
1118
|
}];
|
|
1172
1119
|
} else {
|
|
1173
1120
|
callback(@[@"Not support in this device", [NSNull null]]);
|
|
@@ -1190,7 +1137,7 @@ RCT_EXPORT_METHOD(iso15693_sendRequest:(NSDictionary *)options callback:(nonnull
|
|
|
1190
1137
|
|
|
1191
1138
|
NSInteger flags = [[options objectForKey:@"flags"] integerValue];
|
|
1192
1139
|
NSInteger commandCode = [[options objectForKey:@"commandCode"] integerValue];
|
|
1193
|
-
NSData *data =
|
|
1140
|
+
NSData *data = arrayToData([options mutableArrayValueForKey:@"data"]);
|
|
1194
1141
|
|
|
1195
1142
|
[tag sendRequestWithFlag:flags
|
|
1196
1143
|
commandCode:commandCode
|
|
@@ -1200,7 +1147,7 @@ RCT_EXPORT_METHOD(iso15693_sendRequest:(NSDictionary *)options callback:(nonnull
|
|
|
1200
1147
|
callback(@[getErrorMessage(error), [NSNull null]]);
|
|
1201
1148
|
return;
|
|
1202
1149
|
}
|
|
1203
|
-
callback(@[[NSNull null], [NSNumber numberWithLong:responseFlag],
|
|
1150
|
+
callback(@[[NSNull null], [NSNumber numberWithLong:responseFlag], dataToArray(resp)]);
|
|
1204
1151
|
}];
|
|
1205
1152
|
} else {
|
|
1206
1153
|
callback(@[@"Not support in this device", [NSNull null]]);
|
|
@@ -1209,7 +1156,7 @@ RCT_EXPORT_METHOD(iso15693_sendRequest:(NSDictionary *)options callback:(nonnull
|
|
|
1209
1156
|
|
|
1210
1157
|
RCT_EXPORT_METHOD(iso15693_extendedReadSingleBlock:(NSDictionary *)options callback:(nonnull RCTResponseSenderBlock)callback)
|
|
1211
1158
|
{
|
|
1212
|
-
if (@available(iOS
|
|
1159
|
+
if (@available(iOS 14.0, *)) {
|
|
1213
1160
|
if (!tagSession || !tagSession.connectedTag) {
|
|
1214
1161
|
callback(@[@"Not connected", [NSNull null]]);
|
|
1215
1162
|
return;
|
|
@@ -1232,7 +1179,7 @@ RCT_EXPORT_METHOD(iso15693_extendedReadSingleBlock:(NSDictionary *)options callb
|
|
|
1232
1179
|
return;
|
|
1233
1180
|
}
|
|
1234
1181
|
|
|
1235
|
-
callback(@[[NSNull null],
|
|
1182
|
+
callback(@[[NSNull null], dataToArray(resp)]);
|
|
1236
1183
|
}];
|
|
1237
1184
|
} else {
|
|
1238
1185
|
callback(@[@"Not support in this device", [NSNull null]]);
|
|
@@ -1241,7 +1188,7 @@ RCT_EXPORT_METHOD(iso15693_extendedReadSingleBlock:(NSDictionary *)options callb
|
|
|
1241
1188
|
|
|
1242
1189
|
RCT_EXPORT_METHOD(iso15693_extendedWriteSingleBlock:(NSDictionary *)options callback:(nonnull RCTResponseSenderBlock)callback)
|
|
1243
1190
|
{
|
|
1244
|
-
if (@available(iOS
|
|
1191
|
+
if (@available(iOS 14.0, *)) {
|
|
1245
1192
|
if (!tagSession || !tagSession.connectedTag) {
|
|
1246
1193
|
callback(@[@"Not connected", [NSNull null]]);
|
|
1247
1194
|
return;
|
|
@@ -1255,7 +1202,7 @@ RCT_EXPORT_METHOD(iso15693_extendedWriteSingleBlock:(NSDictionary *)options call
|
|
|
1255
1202
|
|
|
1256
1203
|
RequestFlag flags = [[options objectForKey:@"flags"] unsignedIntValue];
|
|
1257
1204
|
uint16_t blockNumber = [[options objectForKey:@"blockNumber"] unsignedIntValue];
|
|
1258
|
-
NSData *dataBlock =
|
|
1205
|
+
NSData *dataBlock = arrayToData([options mutableArrayValueForKey:@"dataBlock"]);
|
|
1259
1206
|
|
|
1260
1207
|
[tag extendedWriteSingleBlockWithRequestFlags:flags
|
|
1261
1208
|
blockNumber:blockNumber
|
|
@@ -1275,7 +1222,7 @@ RCT_EXPORT_METHOD(iso15693_extendedWriteSingleBlock:(NSDictionary *)options call
|
|
|
1275
1222
|
|
|
1276
1223
|
RCT_EXPORT_METHOD(iso15693_extendedLockBlock:(NSDictionary *)options callback:(nonnull RCTResponseSenderBlock)callback)
|
|
1277
1224
|
{
|
|
1278
|
-
if (@available(iOS
|
|
1225
|
+
if (@available(iOS 14.0, *)) {
|
|
1279
1226
|
if (!tagSession || !tagSession.connectedTag) {
|
|
1280
1227
|
callback(@[@"Not connected", [NSNull null]]);
|
|
1281
1228
|
return;
|
package/ios/Util.m
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Util.m
|
|
3
|
+
// react-native-nfc-manager
|
|
4
|
+
//
|
|
5
|
+
// Created by Richie Hsieh on 2022/1/27.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
#import <Foundation/Foundation.h>
|
|
9
|
+
|
|
10
|
+
NSString* getHexString(NSData *data) {
|
|
11
|
+
NSUInteger capacity = data.length * 2;
|
|
12
|
+
NSMutableString *sbuf = [NSMutableString stringWithCapacity:capacity];
|
|
13
|
+
const unsigned char *buf = data.bytes;
|
|
14
|
+
NSInteger i;
|
|
15
|
+
for (i=0; i<data.length; ++i) {
|
|
16
|
+
[sbuf appendFormat:@"%02lX", (unsigned long)buf[i]];
|
|
17
|
+
}
|
|
18
|
+
return sbuf;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
NSString* getErrorMessage(NSError *error) {
|
|
22
|
+
NSDictionary *userInfo = [error userInfo];
|
|
23
|
+
NSError *underlyingError = [userInfo objectForKey:NSUnderlyingErrorKey];
|
|
24
|
+
if (underlyingError != nil) {
|
|
25
|
+
return [NSString stringWithFormat:@"%@:%ld,%@:%ld",
|
|
26
|
+
[error domain], (long)[error code],
|
|
27
|
+
[underlyingError domain], (long)[underlyingError code]];
|
|
28
|
+
}
|
|
29
|
+
return [NSString stringWithFormat:@"%@:%ld",
|
|
30
|
+
[error domain], (long)[error code]];
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
NSData * arrayToData(NSArray *array) {
|
|
34
|
+
Byte bytes[[array count]];
|
|
35
|
+
for (int i = 0; i < [array count]; i++) {
|
|
36
|
+
bytes[i] = [[array objectAtIndex:i] integerValue];
|
|
37
|
+
}
|
|
38
|
+
NSData *payload = [[NSData alloc] initWithBytes:bytes length:[array count]];
|
|
39
|
+
return payload;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
NSArray * dataToArray(NSData *data) {
|
|
43
|
+
const unsigned char *dataBuffer = data ? (const unsigned char *)[data bytes] : NULL;
|
|
44
|
+
|
|
45
|
+
if (!dataBuffer)
|
|
46
|
+
return @[];
|
|
47
|
+
|
|
48
|
+
NSUInteger dataLength = [data length];
|
|
49
|
+
NSMutableArray *array = [NSMutableArray arrayWithCapacity:dataLength];
|
|
50
|
+
|
|
51
|
+
for (int i = 0; i < dataLength; ++i)
|
|
52
|
+
[array addObject:[NSNumber numberWithInteger:dataBuffer[i]]];
|
|
53
|
+
|
|
54
|
+
return array;
|
|
55
|
+
}
|
package/ndef-lib/index.js
CHANGED