react-native-nfc-manager 3.13.5 → 3.14.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/LICENSE +21 -202
- package/android/src/main/java/community/revteltech/nfc/NfcManager.java +185 -184
- package/android/src/main/java/community/revteltech/nfc/TagTechnologyRequest.java +41 -23
- package/android/src/main/java/community/revteltech/nfc/Util.java +20 -36
- package/ios/NfcManager+Felica.m +43 -0
- package/ios/NfcManager+Iso15693.m +562 -0
- package/ios/NfcManager+IsoDep.m +83 -0
- package/ios/NfcManager+Mifare.m +43 -0
- package/ios/NfcManager.h +2 -2
- package/ios/NfcManager.m +0 -687
- package/package.json +2 -2
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
package community.revteltech.nfc;
|
|
2
|
-
|
|
3
|
-
import android.nfc.NfcAdapter;
|
|
2
|
+
|
|
4
3
|
import android.nfc.Tag;
|
|
5
|
-
import android.nfc.TagLostException;
|
|
6
4
|
import android.nfc.tech.TagTechnology;
|
|
7
5
|
import android.nfc.tech.Ndef;
|
|
8
6
|
import android.nfc.tech.NfcA;
|
|
@@ -34,8 +32,18 @@ class TagTechnologyRequest {
|
|
|
34
32
|
return mTechType;
|
|
35
33
|
}
|
|
36
34
|
|
|
37
|
-
|
|
38
|
-
|
|
35
|
+
void invokePendingCallbackWithError(String err) {
|
|
36
|
+
if (mJsCallback != null) {
|
|
37
|
+
mJsCallback.invoke(err);
|
|
38
|
+
mJsCallback = null;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
void invokePendingCallback(String connectedTech) {
|
|
43
|
+
if (mJsCallback != null) {
|
|
44
|
+
mJsCallback.invoke(null, connectedTech);
|
|
45
|
+
mJsCallback = null;
|
|
46
|
+
}
|
|
39
47
|
}
|
|
40
48
|
|
|
41
49
|
TagTechnology getTechHandle() {
|
|
@@ -61,24 +69,34 @@ class TagTechnologyRequest {
|
|
|
61
69
|
for (int i = 0; i < mTechTypes.size(); i++) {
|
|
62
70
|
String techType = (String)mTechTypes.get(i);
|
|
63
71
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
72
|
+
switch (techType) {
|
|
73
|
+
case "Ndef":
|
|
74
|
+
mTech = Ndef.get(tag);
|
|
75
|
+
break;
|
|
76
|
+
case "NfcA":
|
|
77
|
+
mTech = NfcA.get(tag);
|
|
78
|
+
break;
|
|
79
|
+
case "NfcB":
|
|
80
|
+
mTech = NfcB.get(tag);
|
|
81
|
+
break;
|
|
82
|
+
case "NfcF":
|
|
83
|
+
mTech = NfcF.get(tag);
|
|
84
|
+
break;
|
|
85
|
+
case "NfcV":
|
|
86
|
+
mTech = NfcV.get(tag);
|
|
87
|
+
break;
|
|
88
|
+
case "IsoDep":
|
|
89
|
+
mTech = IsoDep.get(tag);
|
|
90
|
+
break;
|
|
91
|
+
case "MifareClassic":
|
|
92
|
+
mTech = MifareClassic.get(tag);
|
|
93
|
+
break;
|
|
94
|
+
case "MifareUltralight":
|
|
95
|
+
mTech = MifareUltralight.get(tag);
|
|
96
|
+
break;
|
|
97
|
+
case "NdefFormatable":
|
|
98
|
+
mTech = NdefFormatable.get(tag);
|
|
99
|
+
break;
|
|
82
100
|
}
|
|
83
101
|
|
|
84
102
|
if (mTech == null) {
|
|
@@ -44,7 +44,7 @@ public class Util {
|
|
|
44
44
|
json.put("canMakeReadOnly", JSONObject.NULL);
|
|
45
45
|
}
|
|
46
46
|
} catch (JSONException e) {
|
|
47
|
-
Log.e(TAG, "Failed to convert ndef into json: " + ndef
|
|
47
|
+
Log.e(TAG, "Failed to convert ndef into json: " + ndef, e);
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
50
|
return json;
|
|
@@ -58,7 +58,7 @@ public class Util {
|
|
|
58
58
|
json.put("id", bytesToHex(tag.getId()));
|
|
59
59
|
json.put("techTypes", new JSONArray(Arrays.asList(tag.getTechList())));
|
|
60
60
|
} catch (JSONException e) {
|
|
61
|
-
Log.e(TAG, "Failed to convert tag into json: " + tag
|
|
61
|
+
Log.e(TAG, "Failed to convert tag into json: " + tag, e);
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
64
|
return json;
|
|
@@ -66,34 +66,26 @@ public class Util {
|
|
|
66
66
|
|
|
67
67
|
static String translateType(String type) {
|
|
68
68
|
String translation;
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
69
|
+
switch (type) {
|
|
70
|
+
case Ndef.NFC_FORUM_TYPE_1:
|
|
71
|
+
translation = "NFC Forum Type 1";
|
|
72
|
+
break;
|
|
73
|
+
case Ndef.NFC_FORUM_TYPE_2:
|
|
74
|
+
translation = "NFC Forum Type 2";
|
|
75
|
+
break;
|
|
76
|
+
case Ndef.NFC_FORUM_TYPE_3:
|
|
77
|
+
translation = "NFC Forum Type 3";
|
|
78
|
+
break;
|
|
79
|
+
case Ndef.NFC_FORUM_TYPE_4:
|
|
80
|
+
translation = "NFC Forum Type 4";
|
|
81
|
+
break;
|
|
82
|
+
default:
|
|
83
|
+
translation = type;
|
|
84
|
+
break;
|
|
79
85
|
}
|
|
80
86
|
return translation;
|
|
81
87
|
}
|
|
82
88
|
|
|
83
|
-
static NdefRecord[] jsonToNdefRecords(String ndefMessageAsJSON) throws JSONException {
|
|
84
|
-
JSONArray jsonRecords = new JSONArray(ndefMessageAsJSON);
|
|
85
|
-
NdefRecord[] records = new NdefRecord[jsonRecords.length()];
|
|
86
|
-
for (int i = 0; i < jsonRecords.length(); i++) {
|
|
87
|
-
JSONObject record = jsonRecords.getJSONObject(i);
|
|
88
|
-
byte tnf = (byte) record.getInt("tnf");
|
|
89
|
-
byte[] type = jsonToByteArray(record.getJSONArray("type"));
|
|
90
|
-
byte[] id = jsonToByteArray(record.getJSONArray("id"));
|
|
91
|
-
byte[] payload = jsonToByteArray(record.getJSONArray("payload"));
|
|
92
|
-
records[i] = new NdefRecord(tnf, type, id, payload);
|
|
93
|
-
}
|
|
94
|
-
return records;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
89
|
static JSONArray byteArrayToJSON(byte[] bytes) {
|
|
98
90
|
JSONArray json = new JSONArray();
|
|
99
91
|
for (byte aByte : bytes) {
|
|
@@ -116,20 +108,12 @@ public class Util {
|
|
|
116
108
|
return new String(hexChars);
|
|
117
109
|
}
|
|
118
110
|
|
|
119
|
-
static byte[] jsonToByteArray(JSONArray json) throws JSONException {
|
|
120
|
-
byte[] b = new byte[json.length()];
|
|
121
|
-
for (int i = 0; i < json.length(); i++) {
|
|
122
|
-
b[i] = (byte) json.getInt(i);
|
|
123
|
-
}
|
|
124
|
-
return b;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
111
|
static JSONArray messageToJSON(NdefMessage message) {
|
|
128
112
|
if (message == null) {
|
|
129
113
|
return null;
|
|
130
114
|
}
|
|
131
115
|
|
|
132
|
-
List<JSONObject> list = new ArrayList
|
|
116
|
+
List<JSONObject> list = new ArrayList<>();
|
|
133
117
|
|
|
134
118
|
for (NdefRecord ndefRecord : message.getRecords()) {
|
|
135
119
|
list.add(recordToJSON(ndefRecord));
|
|
@@ -147,7 +131,7 @@ public class Util {
|
|
|
147
131
|
json.put("payload", byteArrayToJSON(record.getPayload()));
|
|
148
132
|
} catch (JSONException e) {
|
|
149
133
|
//Not sure why this would happen, documentation is unclear.
|
|
150
|
-
Log.e(TAG, "Failed to convert ndef record into json: " + record
|
|
134
|
+
Log.e(TAG, "Failed to convert ndef record into json: " + record, e);
|
|
151
135
|
}
|
|
152
136
|
return json;
|
|
153
137
|
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
#import "NfcManager.h"
|
|
2
|
+
#import "React/RCTBridge.h"
|
|
3
|
+
#import "React/RCTConvert.h"
|
|
4
|
+
#import "React/RCTEventDispatcher.h"
|
|
5
|
+
#import "React/RCTLog.h"
|
|
6
|
+
|
|
7
|
+
@interface NfcManager (Felica)
|
|
8
|
+
@end
|
|
9
|
+
|
|
10
|
+
@implementation NfcManager (Felica)
|
|
11
|
+
|
|
12
|
+
RCT_EXPORT_METHOD(sendFelicaCommand:(NSArray *)bytes callback: (nonnull RCTResponseSenderBlock)callback)
|
|
13
|
+
{
|
|
14
|
+
if (@available(iOS 13.0, *)) {
|
|
15
|
+
if ([self tagSession] != nil) {
|
|
16
|
+
if ([self tagSession].connectedTag) {
|
|
17
|
+
id<NFCFeliCaTag> felicaTag = [[self tagSession].connectedTag asNFCFeliCaTag];
|
|
18
|
+
NSData *data = arrayToData(bytes);
|
|
19
|
+
NSLog(@"input bytes: %@", getHexString(data));
|
|
20
|
+
if (felicaTag) {
|
|
21
|
+
[felicaTag sendFeliCaCommandPacket:data
|
|
22
|
+
completionHandler:^(NSData *response, NSError *error) {
|
|
23
|
+
if (error) {
|
|
24
|
+
callback(@[getErrorMessage(error), [NSNull null]]);
|
|
25
|
+
} else {
|
|
26
|
+
callback(@[[NSNull null], dataToArray(response)]);
|
|
27
|
+
}
|
|
28
|
+
}];
|
|
29
|
+
return;
|
|
30
|
+
} else {
|
|
31
|
+
callback(@[@"not a felica tag", [NSNull null]]);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
callback(@[@"Not connected", [NSNull null]]);
|
|
35
|
+
} else {
|
|
36
|
+
callback(@[@"Not even registered", [NSNull null]]);
|
|
37
|
+
}
|
|
38
|
+
} else {
|
|
39
|
+
callback(@[@"Not support in this device", [NSNull null]]);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
@end
|