@iotize/device-com-nfc.cordova 3.8.1 → 3.9.0
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 +30 -30
- package/README.md +673 -673
- package/bundles/iotize-device-com-nfc.cordova.umd.js +1108 -967
- package/bundles/iotize-device-com-nfc.cordova.umd.js.map +1 -1
- package/bundles/iotize-device-com-nfc.cordova.umd.min.js +1 -1
- package/bundles/iotize-device-com-nfc.cordova.umd.min.js.map +1 -1
- package/esm2015/iotize-device-com-nfc.cordova.js +4 -4
- package/esm2015/iotize-device-com-nfc.cordova.ngsummary.json +1 -1
- package/esm2015/public_api.js +1 -1
- package/esm2015/public_api.ngsummary.json +1 -1
- package/esm2015/www/cordova-interface.js +1 -1
- package/esm2015/www/cordova-interface.js.map +1 -1
- package/esm2015/www/errors.js +30 -30
- package/esm2015/www/errors.js.map +1 -1
- package/esm2015/www/index.js +6 -6
- package/esm2015/www/index.js.map +1 -1
- package/esm2015/www/index.metadata.json +1 -1
- package/esm2015/www/index.ngsummary.json +1 -1
- package/esm2015/www/logger.js +2 -2
- package/esm2015/www/logger.js.map +1 -1
- package/esm2015/www/ndef/definitions.js +16 -16
- package/esm2015/www/ndef/definitions.js.map +1 -1
- package/esm2015/www/ndef/parse-ndef-message.js +293 -164
- package/esm2015/www/ndef/parse-ndef-message.js.map +1 -1
- package/esm2015/www/ndef/parse-ndef-message.metadata.json +1 -1
- package/esm2015/www/ndef/parse-ndef-message.ngsummary.json +1 -1
- package/esm2015/www/nfc-com-protocol.js +169 -169
- package/esm2015/www/nfc-com-protocol.js.map +1 -1
- package/esm2015/www/tap-ndef/definitions.js +1 -1
- package/esm2015/www/tap-ndef/definitions.js.map +1 -1
- package/esm2015/www/tap-ndef/index.js +2 -2
- package/esm2015/www/tap-ndef/index.js.map +1 -1
- package/esm2015/www/tap-ndef/parse-ndef-message.js +51 -51
- package/esm2015/www/tap-ndef/parse-ndef-message.js.map +1 -1
- package/esm2015/www/utility.js +10 -10
- package/esm2015/www/utility.js.map +1 -1
- package/esm2015/www/utility.ngsummary.json +1 -1
- package/fesm2015/iotize-device-com-nfc.cordova.js +555 -427
- package/fesm2015/iotize-device-com-nfc.cordova.js.map +1 -1
- package/iotize-device-com-nfc.cordova.d.ts +4 -4
- package/iotize-device-com-nfc.cordova.metadata.json +1 -1
- package/package.json +2 -2
- package/plugin.xml +98 -98
- package/public_api.d.ts +1 -1
- package/src/android/.gradle/4.10.1/fileChanges/last-build.bin +0 -0
- package/src/android/.gradle/4.10.1/fileHashes/fileHashes.bin +0 -0
- package/src/android/.gradle/4.10.1/fileHashes/fileHashes.lock +0 -0
- package/src/android/.gradle/4.10.1/gc.properties +0 -0
- package/src/android/build.gradle +38 -38
- package/src/android/gradle/wrapper/gradle-wrapper.properties +6 -6
- package/src/android/gradlew +172 -172
- package/src/android/gradlew.bat +84 -84
- package/src/android/local.properties +8 -8
- package/src/android/src/com/chariotsolutions/nfc/plugin/JSONBuilder.java +60 -60
- package/src/android/src/com/chariotsolutions/nfc/plugin/NfcPlugin.java +1151 -1151
- package/src/android/src/com/chariotsolutions/nfc/plugin/NfcPluginError.java +15 -15
- package/src/android/src/com/chariotsolutions/nfc/plugin/PluginResponse.java +85 -85
- package/src/android/src/com/chariotsolutions/nfc/plugin/Util.java +140 -140
- package/src/ios/AppDelegate+NFC.swift +51 -51
- package/src/ios/NFCHelpers.swift +144 -144
- package/src/ios/NFCNDEFDelegate.swift +78 -78
- package/src/ios/NFCTagReader.swift +506 -506
- package/www/cordova-interface.d.ts +34 -34
- package/www/errors.d.ts +17 -17
- package/www/index.d.ts +6 -6
- package/www/logger.d.ts +2 -2
- package/www/ndef/definitions.d.ts +15 -15
- package/www/ndef/parse-ndef-message.d.ts +12 -69
- package/www/nfc-com-protocol.d.ts +36 -36
- package/www/phonegap-nfc.js +911 -911
- package/www/tap-ndef/definitions.d.ts +25 -25
- package/www/tap-ndef/index.d.ts +2 -2
- package/www/tap-ndef/parse-ndef-message.d.ts +6 -6
- package/www/utility.d.ts +2 -2
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
package com.chariotsolutions.nfc.plugin;
|
|
2
|
-
|
|
3
|
-
class NfcPluginError extends Exception {
|
|
4
|
-
|
|
5
|
-
String code;
|
|
6
|
-
|
|
7
|
-
public String getCode() {
|
|
8
|
-
return code;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
public NfcPluginError(String code, String message, Throwable cause) {
|
|
12
|
-
super(message, cause);
|
|
13
|
-
this.code = code;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
1
|
+
package com.chariotsolutions.nfc.plugin;
|
|
2
|
+
|
|
3
|
+
class NfcPluginError extends Exception {
|
|
4
|
+
|
|
5
|
+
String code;
|
|
6
|
+
|
|
7
|
+
public String getCode() {
|
|
8
|
+
return code;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
public NfcPluginError(String code, String message, Throwable cause) {
|
|
12
|
+
super(message, cause);
|
|
13
|
+
this.code = code;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -1,85 +1,85 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2018 IoTize SAS Inc. Licensed under the MIT license.
|
|
3
|
-
//
|
|
4
|
-
// PluginResponse.java
|
|
5
|
-
// device-com-ble.cordova BLE Cordova Plugin
|
|
6
|
-
//
|
|
7
|
-
package com.chariotsolutions.nfc.plugin;
|
|
8
|
-
|
|
9
|
-
import com.iotize.android.core.util.Helper;
|
|
10
|
-
|
|
11
|
-
import org.apache.cordova.CallbackContext;
|
|
12
|
-
import org.apache.cordova.PluginResult;
|
|
13
|
-
import org.json.JSONArray;
|
|
14
|
-
import org.json.JSONObject;
|
|
15
|
-
|
|
16
|
-
public class PluginResponse {
|
|
17
|
-
|
|
18
|
-
private static final String TAG = "PluginResponse";
|
|
19
|
-
private final CallbackContext callbackContext;
|
|
20
|
-
private final String action;
|
|
21
|
-
|
|
22
|
-
public PluginResponse(String action, JSONArray args, CallbackContext callbackContext) {
|
|
23
|
-
this.callbackContext = callbackContext;
|
|
24
|
-
this.action = action;
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
public void newResult(String data) {
|
|
29
|
-
PluginResult result = new PluginResult(
|
|
30
|
-
PluginResult.Status.OK,
|
|
31
|
-
data
|
|
32
|
-
);
|
|
33
|
-
result.setKeepCallback(true);
|
|
34
|
-
this.callbackContext.sendPluginResult(result);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
public void newResult(JSONObject data) {
|
|
38
|
-
PluginResult result = new PluginResult(
|
|
39
|
-
PluginResult.Status.OK,
|
|
40
|
-
data
|
|
41
|
-
);
|
|
42
|
-
result.setKeepCallback(true);
|
|
43
|
-
this.callbackContext.sendPluginResult(result);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
public void newResult(NfcPluginError error) {
|
|
47
|
-
this.callbackContext.sendPluginResult(new PluginResult(
|
|
48
|
-
PluginResult.Status.ERROR,
|
|
49
|
-
JSONBuilder.toJSONObject(error)
|
|
50
|
-
));
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
public void success(JSONObject object) {
|
|
54
|
-
this.callbackContext.success(object);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
public void success(byte[] response) {
|
|
58
|
-
this.callbackContext.success(Helper.ByteArrayToHexString(response));
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
public void error(NfcPluginError err) {
|
|
62
|
-
JSONObject object = JSONBuilder.toJSONObject(err);
|
|
63
|
-
this.callbackContext.error(object);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
public void success(boolean isConnected) {
|
|
67
|
-
this.callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, isConnected)); }
|
|
68
|
-
|
|
69
|
-
public void success() {
|
|
70
|
-
this.callbackContext.success();
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
public void error(String message) {
|
|
74
|
-
this.callbackContext.success(message);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
public void success(String msg) {
|
|
78
|
-
this.callbackContext.success(msg);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
public CallbackContext getCallbackContext() {
|
|
82
|
-
return callbackContext;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
}
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2018 IoTize SAS Inc. Licensed under the MIT license.
|
|
3
|
+
//
|
|
4
|
+
// PluginResponse.java
|
|
5
|
+
// device-com-ble.cordova BLE Cordova Plugin
|
|
6
|
+
//
|
|
7
|
+
package com.chariotsolutions.nfc.plugin;
|
|
8
|
+
|
|
9
|
+
import com.iotize.android.core.util.Helper;
|
|
10
|
+
|
|
11
|
+
import org.apache.cordova.CallbackContext;
|
|
12
|
+
import org.apache.cordova.PluginResult;
|
|
13
|
+
import org.json.JSONArray;
|
|
14
|
+
import org.json.JSONObject;
|
|
15
|
+
|
|
16
|
+
public class PluginResponse {
|
|
17
|
+
|
|
18
|
+
private static final String TAG = "PluginResponse";
|
|
19
|
+
private final CallbackContext callbackContext;
|
|
20
|
+
private final String action;
|
|
21
|
+
|
|
22
|
+
public PluginResponse(String action, JSONArray args, CallbackContext callbackContext) {
|
|
23
|
+
this.callbackContext = callbackContext;
|
|
24
|
+
this.action = action;
|
|
25
|
+
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
public void newResult(String data) {
|
|
29
|
+
PluginResult result = new PluginResult(
|
|
30
|
+
PluginResult.Status.OK,
|
|
31
|
+
data
|
|
32
|
+
);
|
|
33
|
+
result.setKeepCallback(true);
|
|
34
|
+
this.callbackContext.sendPluginResult(result);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
public void newResult(JSONObject data) {
|
|
38
|
+
PluginResult result = new PluginResult(
|
|
39
|
+
PluginResult.Status.OK,
|
|
40
|
+
data
|
|
41
|
+
);
|
|
42
|
+
result.setKeepCallback(true);
|
|
43
|
+
this.callbackContext.sendPluginResult(result);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
public void newResult(NfcPluginError error) {
|
|
47
|
+
this.callbackContext.sendPluginResult(new PluginResult(
|
|
48
|
+
PluginResult.Status.ERROR,
|
|
49
|
+
JSONBuilder.toJSONObject(error)
|
|
50
|
+
));
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
public void success(JSONObject object) {
|
|
54
|
+
this.callbackContext.success(object);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
public void success(byte[] response) {
|
|
58
|
+
this.callbackContext.success(Helper.ByteArrayToHexString(response));
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
public void error(NfcPluginError err) {
|
|
62
|
+
JSONObject object = JSONBuilder.toJSONObject(err);
|
|
63
|
+
this.callbackContext.error(object);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
public void success(boolean isConnected) {
|
|
67
|
+
this.callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, isConnected)); }
|
|
68
|
+
|
|
69
|
+
public void success() {
|
|
70
|
+
this.callbackContext.success();
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
public void error(String message) {
|
|
74
|
+
this.callbackContext.success(message);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
public void success(String msg) {
|
|
78
|
+
this.callbackContext.success(msg);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
public CallbackContext getCallbackContext() {
|
|
82
|
+
return callbackContext;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
}
|
|
@@ -1,140 +1,140 @@
|
|
|
1
|
-
package com.chariotsolutions.nfc.plugin;
|
|
2
|
-
|
|
3
|
-
import android.nfc.NdefMessage;
|
|
4
|
-
import android.nfc.NdefRecord;
|
|
5
|
-
import android.nfc.Tag;
|
|
6
|
-
import android.nfc.tech.Ndef;
|
|
7
|
-
import android.util.Log;
|
|
8
|
-
import org.json.JSONArray;
|
|
9
|
-
import org.json.JSONException;
|
|
10
|
-
import org.json.JSONObject;
|
|
11
|
-
|
|
12
|
-
import java.util.ArrayList;
|
|
13
|
-
import java.util.Arrays;
|
|
14
|
-
import java.util.List;
|
|
15
|
-
|
|
16
|
-
public class Util {
|
|
17
|
-
|
|
18
|
-
static final String TAG = "NfcPlugin";
|
|
19
|
-
|
|
20
|
-
static JSONObject ndefToJSON(Ndef ndef) {
|
|
21
|
-
JSONObject json = new JSONObject();
|
|
22
|
-
|
|
23
|
-
if (ndef != null) {
|
|
24
|
-
try {
|
|
25
|
-
|
|
26
|
-
Tag tag = ndef.getTag();
|
|
27
|
-
// tag is going to be null for NDEF_FORMATABLE until NfcUtil.parseMessage is refactored
|
|
28
|
-
if (tag != null) {
|
|
29
|
-
json.put("id", byteArrayToJSON(tag.getId()));
|
|
30
|
-
json.put("techTypes", new JSONArray(Arrays.asList(tag.getTechList())));
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
json.put("type", translateType(ndef.getType()));
|
|
34
|
-
json.put("maxSize", ndef.getMaxSize());
|
|
35
|
-
json.put("isWritable", ndef.isWritable());
|
|
36
|
-
json.put("ndefMessage", messageToJSON(ndef.getCachedNdefMessage()));
|
|
37
|
-
// Workaround for bug in ICS (Android 4.0 and 4.0.1) where
|
|
38
|
-
// mTag.getTagService(); of the Ndef object sometimes returns null
|
|
39
|
-
// see http://issues.mroland.at/index.php?do=details&task_id=47
|
|
40
|
-
try {
|
|
41
|
-
json.put("canMakeReadOnly", ndef.canMakeReadOnly());
|
|
42
|
-
} catch (NullPointerException e) {
|
|
43
|
-
json.put("canMakeReadOnly", JSONObject.NULL);
|
|
44
|
-
}
|
|
45
|
-
} catch (JSONException e) {
|
|
46
|
-
Log.e(TAG, "Failed to convert ndef into json: " + ndef.toString(), e);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
return json;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
static JSONObject tagToJSON(Tag tag) {
|
|
53
|
-
JSONObject json = new JSONObject();
|
|
54
|
-
|
|
55
|
-
if (tag != null) {
|
|
56
|
-
try {
|
|
57
|
-
json.put("id", byteArrayToJSON(tag.getId()));
|
|
58
|
-
json.put("techTypes", new JSONArray(Arrays.asList(tag.getTechList())));
|
|
59
|
-
} catch (JSONException e) {
|
|
60
|
-
Log.e(TAG, "Failed to convert tag into json: " + tag.toString(), e);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
return json;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
static String translateType(String type) {
|
|
67
|
-
String translation;
|
|
68
|
-
if (type.equals(Ndef.NFC_FORUM_TYPE_1)) {
|
|
69
|
-
translation = "NFC Forum Type 1";
|
|
70
|
-
} else if (type.equals(Ndef.NFC_FORUM_TYPE_2)) {
|
|
71
|
-
translation = "NFC Forum Type 2";
|
|
72
|
-
} else if (type.equals(Ndef.NFC_FORUM_TYPE_3)) {
|
|
73
|
-
translation = "NFC Forum Type 3";
|
|
74
|
-
} else if (type.equals(Ndef.NFC_FORUM_TYPE_4)) {
|
|
75
|
-
translation = "NFC Forum Type 4";
|
|
76
|
-
} else {
|
|
77
|
-
translation = type;
|
|
78
|
-
}
|
|
79
|
-
return translation;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
static NdefRecord[] jsonToNdefRecords(String ndefMessageAsJSON) throws JSONException {
|
|
83
|
-
JSONArray jsonRecords = new JSONArray(ndefMessageAsJSON);
|
|
84
|
-
NdefRecord[] records = new NdefRecord[jsonRecords.length()];
|
|
85
|
-
for (int i = 0; i < jsonRecords.length(); i++) {
|
|
86
|
-
JSONObject record = jsonRecords.getJSONObject(i);
|
|
87
|
-
byte tnf = (byte) record.getInt("tnf");
|
|
88
|
-
byte[] type = jsonToByteArray(record.getJSONArray("type"));
|
|
89
|
-
byte[] id = jsonToByteArray(record.getJSONArray("id"));
|
|
90
|
-
byte[] payload = jsonToByteArray(record.getJSONArray("payload"));
|
|
91
|
-
records[i] = new NdefRecord(tnf, type, id, payload);
|
|
92
|
-
}
|
|
93
|
-
return records;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
static JSONArray byteArrayToJSON(byte[] bytes) {
|
|
97
|
-
JSONArray json = new JSONArray();
|
|
98
|
-
for (byte aByte : bytes) {
|
|
99
|
-
json.put(aByte);
|
|
100
|
-
}
|
|
101
|
-
return json;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
static byte[] jsonToByteArray(JSONArray json) throws JSONException {
|
|
105
|
-
byte[] b = new byte[json.length()];
|
|
106
|
-
for (int i = 0; i < json.length(); i++) {
|
|
107
|
-
b[i] = (byte) json.getInt(i);
|
|
108
|
-
}
|
|
109
|
-
return b;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
static JSONArray messageToJSON(NdefMessage message) {
|
|
113
|
-
if (message == null) {
|
|
114
|
-
return null;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
List<JSONObject> list = new ArrayList<JSONObject>();
|
|
118
|
-
|
|
119
|
-
for (NdefRecord ndefRecord : message.getRecords()) {
|
|
120
|
-
list.add(recordToJSON(ndefRecord));
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
return new JSONArray(list);
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
static JSONObject recordToJSON(NdefRecord record) {
|
|
127
|
-
JSONObject json = new JSONObject();
|
|
128
|
-
try {
|
|
129
|
-
json.put("tnf", record.getTnf());
|
|
130
|
-
json.put("type", byteArrayToJSON(record.getType()));
|
|
131
|
-
json.put("id", byteArrayToJSON(record.getId()));
|
|
132
|
-
json.put("payload", byteArrayToJSON(record.getPayload()));
|
|
133
|
-
} catch (JSONException e) {
|
|
134
|
-
//Not sure why this would happen, documentation is unclear.
|
|
135
|
-
Log.e(TAG, "Failed to convert ndef record into json: " + record.toString(), e);
|
|
136
|
-
}
|
|
137
|
-
return json;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
}
|
|
1
|
+
package com.chariotsolutions.nfc.plugin;
|
|
2
|
+
|
|
3
|
+
import android.nfc.NdefMessage;
|
|
4
|
+
import android.nfc.NdefRecord;
|
|
5
|
+
import android.nfc.Tag;
|
|
6
|
+
import android.nfc.tech.Ndef;
|
|
7
|
+
import android.util.Log;
|
|
8
|
+
import org.json.JSONArray;
|
|
9
|
+
import org.json.JSONException;
|
|
10
|
+
import org.json.JSONObject;
|
|
11
|
+
|
|
12
|
+
import java.util.ArrayList;
|
|
13
|
+
import java.util.Arrays;
|
|
14
|
+
import java.util.List;
|
|
15
|
+
|
|
16
|
+
public class Util {
|
|
17
|
+
|
|
18
|
+
static final String TAG = "NfcPlugin";
|
|
19
|
+
|
|
20
|
+
static JSONObject ndefToJSON(Ndef ndef) {
|
|
21
|
+
JSONObject json = new JSONObject();
|
|
22
|
+
|
|
23
|
+
if (ndef != null) {
|
|
24
|
+
try {
|
|
25
|
+
|
|
26
|
+
Tag tag = ndef.getTag();
|
|
27
|
+
// tag is going to be null for NDEF_FORMATABLE until NfcUtil.parseMessage is refactored
|
|
28
|
+
if (tag != null) {
|
|
29
|
+
json.put("id", byteArrayToJSON(tag.getId()));
|
|
30
|
+
json.put("techTypes", new JSONArray(Arrays.asList(tag.getTechList())));
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
json.put("type", translateType(ndef.getType()));
|
|
34
|
+
json.put("maxSize", ndef.getMaxSize());
|
|
35
|
+
json.put("isWritable", ndef.isWritable());
|
|
36
|
+
json.put("ndefMessage", messageToJSON(ndef.getCachedNdefMessage()));
|
|
37
|
+
// Workaround for bug in ICS (Android 4.0 and 4.0.1) where
|
|
38
|
+
// mTag.getTagService(); of the Ndef object sometimes returns null
|
|
39
|
+
// see http://issues.mroland.at/index.php?do=details&task_id=47
|
|
40
|
+
try {
|
|
41
|
+
json.put("canMakeReadOnly", ndef.canMakeReadOnly());
|
|
42
|
+
} catch (NullPointerException e) {
|
|
43
|
+
json.put("canMakeReadOnly", JSONObject.NULL);
|
|
44
|
+
}
|
|
45
|
+
} catch (JSONException e) {
|
|
46
|
+
Log.e(TAG, "Failed to convert ndef into json: " + ndef.toString(), e);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return json;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
static JSONObject tagToJSON(Tag tag) {
|
|
53
|
+
JSONObject json = new JSONObject();
|
|
54
|
+
|
|
55
|
+
if (tag != null) {
|
|
56
|
+
try {
|
|
57
|
+
json.put("id", byteArrayToJSON(tag.getId()));
|
|
58
|
+
json.put("techTypes", new JSONArray(Arrays.asList(tag.getTechList())));
|
|
59
|
+
} catch (JSONException e) {
|
|
60
|
+
Log.e(TAG, "Failed to convert tag into json: " + tag.toString(), e);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return json;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
static String translateType(String type) {
|
|
67
|
+
String translation;
|
|
68
|
+
if (type.equals(Ndef.NFC_FORUM_TYPE_1)) {
|
|
69
|
+
translation = "NFC Forum Type 1";
|
|
70
|
+
} else if (type.equals(Ndef.NFC_FORUM_TYPE_2)) {
|
|
71
|
+
translation = "NFC Forum Type 2";
|
|
72
|
+
} else if (type.equals(Ndef.NFC_FORUM_TYPE_3)) {
|
|
73
|
+
translation = "NFC Forum Type 3";
|
|
74
|
+
} else if (type.equals(Ndef.NFC_FORUM_TYPE_4)) {
|
|
75
|
+
translation = "NFC Forum Type 4";
|
|
76
|
+
} else {
|
|
77
|
+
translation = type;
|
|
78
|
+
}
|
|
79
|
+
return translation;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
static NdefRecord[] jsonToNdefRecords(String ndefMessageAsJSON) throws JSONException {
|
|
83
|
+
JSONArray jsonRecords = new JSONArray(ndefMessageAsJSON);
|
|
84
|
+
NdefRecord[] records = new NdefRecord[jsonRecords.length()];
|
|
85
|
+
for (int i = 0; i < jsonRecords.length(); i++) {
|
|
86
|
+
JSONObject record = jsonRecords.getJSONObject(i);
|
|
87
|
+
byte tnf = (byte) record.getInt("tnf");
|
|
88
|
+
byte[] type = jsonToByteArray(record.getJSONArray("type"));
|
|
89
|
+
byte[] id = jsonToByteArray(record.getJSONArray("id"));
|
|
90
|
+
byte[] payload = jsonToByteArray(record.getJSONArray("payload"));
|
|
91
|
+
records[i] = new NdefRecord(tnf, type, id, payload);
|
|
92
|
+
}
|
|
93
|
+
return records;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
static JSONArray byteArrayToJSON(byte[] bytes) {
|
|
97
|
+
JSONArray json = new JSONArray();
|
|
98
|
+
for (byte aByte : bytes) {
|
|
99
|
+
json.put(aByte);
|
|
100
|
+
}
|
|
101
|
+
return json;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
static byte[] jsonToByteArray(JSONArray json) throws JSONException {
|
|
105
|
+
byte[] b = new byte[json.length()];
|
|
106
|
+
for (int i = 0; i < json.length(); i++) {
|
|
107
|
+
b[i] = (byte) json.getInt(i);
|
|
108
|
+
}
|
|
109
|
+
return b;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
static JSONArray messageToJSON(NdefMessage message) {
|
|
113
|
+
if (message == null) {
|
|
114
|
+
return null;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
List<JSONObject> list = new ArrayList<JSONObject>();
|
|
118
|
+
|
|
119
|
+
for (NdefRecord ndefRecord : message.getRecords()) {
|
|
120
|
+
list.add(recordToJSON(ndefRecord));
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
return new JSONArray(list);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
static JSONObject recordToJSON(NdefRecord record) {
|
|
127
|
+
JSONObject json = new JSONObject();
|
|
128
|
+
try {
|
|
129
|
+
json.put("tnf", record.getTnf());
|
|
130
|
+
json.put("type", byteArrayToJSON(record.getType()));
|
|
131
|
+
json.put("id", byteArrayToJSON(record.getId()));
|
|
132
|
+
json.put("payload", byteArrayToJSON(record.getPayload()));
|
|
133
|
+
} catch (JSONException e) {
|
|
134
|
+
//Not sure why this would happen, documentation is unclear.
|
|
135
|
+
Log.e(TAG, "Failed to convert ndef record into json: " + record.toString(), e);
|
|
136
|
+
}
|
|
137
|
+
return json;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
}
|
|
@@ -1,51 +1,51 @@
|
|
|
1
|
-
//
|
|
2
|
-
// AppDelegate+NFC.swift
|
|
3
|
-
// PhoneGap NFC - Cordova Plugin
|
|
4
|
-
//
|
|
5
|
-
// Copyright © 2019 dev@iotize.com. All rights reserved.
|
|
6
|
-
|
|
7
|
-
import CoreNFC
|
|
8
|
-
|
|
9
|
-
extension AppDelegate {
|
|
10
|
-
|
|
11
|
-
override open func application(_ application: UIApplication,
|
|
12
|
-
continue userActivity: NSUserActivity,
|
|
13
|
-
restorationHandler: @escaping ([Any]?) -> Void) -> Bool {
|
|
14
|
-
|
|
15
|
-
NSLog("Extending UIApplicationDelegate")
|
|
16
|
-
|
|
17
|
-
guard userActivity.activityType == NSUserActivityTypeBrowsingWeb else {
|
|
18
|
-
return false
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
// Confirm that the NSUserActivity object contains a valid NDEF message.
|
|
22
|
-
if #available(iOS 12.0, *) {
|
|
23
|
-
let ndefMessage = userActivity.ndefMessagePayload
|
|
24
|
-
guard ndefMessage.records.count > 0,
|
|
25
|
-
ndefMessage.records[0].typeNameFormat != .empty else {
|
|
26
|
-
return false
|
|
27
|
-
}
|
|
28
|
-
let nfcPluginInstance: NfcPlugin = self.viewController.getCommandInstance("NfcPlugin") as! NfcPlugin
|
|
29
|
-
var resolved: Bool = false;
|
|
30
|
-
NSLog(nfcPluginInstance.debugDescription);
|
|
31
|
-
|
|
32
|
-
DispatchQueue.global().async {
|
|
33
|
-
let waitingTimeInterval: Double = 0.1;
|
|
34
|
-
print("<NFC> Did start timeout")
|
|
35
|
-
for _ in 1...2000 { // 5?s timeout
|
|
36
|
-
if ( !nfcPluginInstance.isListeningNDEF ) {
|
|
37
|
-
Thread.sleep(forTimeInterval: waitingTimeInterval)
|
|
38
|
-
} else {
|
|
39
|
-
let jsonDictionary = ndefMessage.ndefMessageToJSON()
|
|
40
|
-
nfcPluginInstance.sendThroughChannel(jsonDictionary: jsonDictionary)
|
|
41
|
-
resolved = true
|
|
42
|
-
return
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
return resolved
|
|
47
|
-
} else {
|
|
48
|
-
return false
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
}
|
|
1
|
+
//
|
|
2
|
+
// AppDelegate+NFC.swift
|
|
3
|
+
// PhoneGap NFC - Cordova Plugin
|
|
4
|
+
//
|
|
5
|
+
// Copyright © 2019 dev@iotize.com. All rights reserved.
|
|
6
|
+
|
|
7
|
+
import CoreNFC
|
|
8
|
+
|
|
9
|
+
extension AppDelegate {
|
|
10
|
+
|
|
11
|
+
override open func application(_ application: UIApplication,
|
|
12
|
+
continue userActivity: NSUserActivity,
|
|
13
|
+
restorationHandler: @escaping ([Any]?) -> Void) -> Bool {
|
|
14
|
+
|
|
15
|
+
NSLog("Extending UIApplicationDelegate")
|
|
16
|
+
|
|
17
|
+
guard userActivity.activityType == NSUserActivityTypeBrowsingWeb else {
|
|
18
|
+
return false
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// Confirm that the NSUserActivity object contains a valid NDEF message.
|
|
22
|
+
if #available(iOS 12.0, *) {
|
|
23
|
+
let ndefMessage = userActivity.ndefMessagePayload
|
|
24
|
+
guard ndefMessage.records.count > 0,
|
|
25
|
+
ndefMessage.records[0].typeNameFormat != .empty else {
|
|
26
|
+
return false
|
|
27
|
+
}
|
|
28
|
+
let nfcPluginInstance: NfcPlugin = self.viewController.getCommandInstance("NfcPlugin") as! NfcPlugin
|
|
29
|
+
var resolved: Bool = false;
|
|
30
|
+
NSLog(nfcPluginInstance.debugDescription);
|
|
31
|
+
|
|
32
|
+
DispatchQueue.global().async {
|
|
33
|
+
let waitingTimeInterval: Double = 0.1;
|
|
34
|
+
print("<NFC> Did start timeout")
|
|
35
|
+
for _ in 1...2000 { // 5?s timeout
|
|
36
|
+
if ( !nfcPluginInstance.isListeningNDEF ) {
|
|
37
|
+
Thread.sleep(forTimeInterval: waitingTimeInterval)
|
|
38
|
+
} else {
|
|
39
|
+
let jsonDictionary = ndefMessage.ndefMessageToJSON()
|
|
40
|
+
nfcPluginInstance.sendThroughChannel(jsonDictionary: jsonDictionary)
|
|
41
|
+
resolved = true
|
|
42
|
+
return
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return resolved
|
|
47
|
+
} else {
|
|
48
|
+
return false
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|