react-native-ble-manager 12.4.4 → 12.5.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/android/src/main/java/it/innove/BleManager.java +80 -0
- package/android/src/main/java/it/innove/CompanionScanner.java +15 -1
- package/android/src/main/java/it/innove/DefaultScanManager.java +15 -2
- package/android/src/main/java/it/innove/UUIDHelper.java +21 -0
- package/ios/Helper.swift +18 -0
- package/ios/SwiftBleManager.swift +117 -18
- package/package.json +1 -1
|
@@ -460,6 +460,15 @@ public class BleManager extends NativeBleManagerSpec {
|
|
|
460
460
|
callback.invoke("ServiceUUID and characteristicUUID required.");
|
|
461
461
|
return;
|
|
462
462
|
}
|
|
463
|
+
// Validate UUID formats to prevent crash
|
|
464
|
+
if (!UUIDHelper.isValidBLEUUID(serviceUUID)) {
|
|
465
|
+
callback.invoke("Invalid service UUID format: " + serviceUUID);
|
|
466
|
+
return;
|
|
467
|
+
}
|
|
468
|
+
if (!UUIDHelper.isValidBLEUUID(characteristicUUID)) {
|
|
469
|
+
callback.invoke("Invalid characteristic UUID format: " + characteristicUUID);
|
|
470
|
+
return;
|
|
471
|
+
}
|
|
463
472
|
Peripheral peripheral = peripherals.get(deviceUUID);
|
|
464
473
|
if (peripheral != null) {
|
|
465
474
|
peripheral.registerNotify(UUIDHelper.uuidFromString(serviceUUID),
|
|
@@ -475,6 +484,15 @@ public class BleManager extends NativeBleManagerSpec {
|
|
|
475
484
|
callback.invoke("ServiceUUID and characteristicUUID required.");
|
|
476
485
|
return;
|
|
477
486
|
}
|
|
487
|
+
// Validate UUID formats to prevent crash
|
|
488
|
+
if (!UUIDHelper.isValidBLEUUID(serviceUUID)) {
|
|
489
|
+
callback.invoke("Invalid service UUID format: " + serviceUUID);
|
|
490
|
+
return;
|
|
491
|
+
}
|
|
492
|
+
if (!UUIDHelper.isValidBLEUUID(characteristicUUID)) {
|
|
493
|
+
callback.invoke("Invalid characteristic UUID format: " + characteristicUUID);
|
|
494
|
+
return;
|
|
495
|
+
}
|
|
478
496
|
Peripheral peripheral = peripherals.get(deviceUUID);
|
|
479
497
|
if (peripheral != null) {
|
|
480
498
|
if (peripheral.isConnected()) {
|
|
@@ -494,6 +512,15 @@ public class BleManager extends NativeBleManagerSpec {
|
|
|
494
512
|
callback.invoke("ServiceUUID and characteristicUUID required.");
|
|
495
513
|
return;
|
|
496
514
|
}
|
|
515
|
+
// Validate UUID formats to prevent crash
|
|
516
|
+
if (!UUIDHelper.isValidBLEUUID(serviceUUID)) {
|
|
517
|
+
callback.invoke("Invalid service UUID format: " + serviceUUID);
|
|
518
|
+
return;
|
|
519
|
+
}
|
|
520
|
+
if (!UUIDHelper.isValidBLEUUID(characteristicUUID)) {
|
|
521
|
+
callback.invoke("Invalid characteristic UUID format: " + characteristicUUID);
|
|
522
|
+
return;
|
|
523
|
+
}
|
|
497
524
|
Peripheral peripheral = peripherals.get(deviceUUID);
|
|
498
525
|
if (peripheral != null) {
|
|
499
526
|
if (peripheral.isConnected()) {
|
|
@@ -514,6 +541,15 @@ public class BleManager extends NativeBleManagerSpec {
|
|
|
514
541
|
callback.invoke("ServiceUUID and characteristicUUID required.");
|
|
515
542
|
return;
|
|
516
543
|
}
|
|
544
|
+
// Validate UUID formats to prevent crash
|
|
545
|
+
if (!UUIDHelper.isValidBLEUUID(serviceUUID)) {
|
|
546
|
+
callback.invoke("Invalid service UUID format: " + serviceUUID);
|
|
547
|
+
return;
|
|
548
|
+
}
|
|
549
|
+
if (!UUIDHelper.isValidBLEUUID(characteristicUUID)) {
|
|
550
|
+
callback.invoke("Invalid characteristic UUID format: " + characteristicUUID);
|
|
551
|
+
return;
|
|
552
|
+
}
|
|
517
553
|
Peripheral peripheral = peripherals.get(deviceUUID);
|
|
518
554
|
if (peripheral != null) {
|
|
519
555
|
if (peripheral.isConnected()) {
|
|
@@ -539,6 +575,15 @@ public class BleManager extends NativeBleManagerSpec {
|
|
|
539
575
|
callback.invoke("ServiceUUID and characteristicUUID required.");
|
|
540
576
|
return;
|
|
541
577
|
}
|
|
578
|
+
// Validate UUID formats to prevent crash
|
|
579
|
+
if (!UUIDHelper.isValidBLEUUID(serviceUUID)) {
|
|
580
|
+
callback.invoke("Invalid service UUID format: " + serviceUUID);
|
|
581
|
+
return;
|
|
582
|
+
}
|
|
583
|
+
if (!UUIDHelper.isValidBLEUUID(characteristicUUID)) {
|
|
584
|
+
callback.invoke("Invalid characteristic UUID format: " + characteristicUUID);
|
|
585
|
+
return;
|
|
586
|
+
}
|
|
542
587
|
Peripheral peripheral = peripherals.get(deviceUUID);
|
|
543
588
|
if (peripheral != null) {
|
|
544
589
|
if (peripheral.isConnected()) {
|
|
@@ -563,6 +608,15 @@ public class BleManager extends NativeBleManagerSpec {
|
|
|
563
608
|
callback.invoke("ServiceUUID and characteristicUUID required.");
|
|
564
609
|
return;
|
|
565
610
|
}
|
|
611
|
+
// Validate UUID formats to prevent crash
|
|
612
|
+
if (!UUIDHelper.isValidBLEUUID(serviceUUID)) {
|
|
613
|
+
callback.invoke("Invalid service UUID format: " + serviceUUID);
|
|
614
|
+
return;
|
|
615
|
+
}
|
|
616
|
+
if (!UUIDHelper.isValidBLEUUID(characteristicUUID)) {
|
|
617
|
+
callback.invoke("Invalid characteristic UUID format: " + characteristicUUID);
|
|
618
|
+
return;
|
|
619
|
+
}
|
|
566
620
|
Peripheral peripheral = peripherals.get(deviceUUID);
|
|
567
621
|
if (peripheral != null) {
|
|
568
622
|
if (peripheral.isConnected()) {
|
|
@@ -582,6 +636,19 @@ public class BleManager extends NativeBleManagerSpec {
|
|
|
582
636
|
callback.invoke("ServiceUUID, CharacteristicUUID and descriptorUUID required.", null);
|
|
583
637
|
return;
|
|
584
638
|
}
|
|
639
|
+
// Validate UUID formats to prevent crash
|
|
640
|
+
if (!UUIDHelper.isValidBLEUUID(serviceUUID)) {
|
|
641
|
+
callback.invoke("Invalid service UUID format: " + serviceUUID, null);
|
|
642
|
+
return;
|
|
643
|
+
}
|
|
644
|
+
if (!UUIDHelper.isValidBLEUUID(characteristicUUID)) {
|
|
645
|
+
callback.invoke("Invalid characteristic UUID format: " + characteristicUUID, null);
|
|
646
|
+
return;
|
|
647
|
+
}
|
|
648
|
+
if (!UUIDHelper.isValidBLEUUID(descriptorUUID)) {
|
|
649
|
+
callback.invoke("Invalid descriptor UUID format: " + descriptorUUID, null);
|
|
650
|
+
return;
|
|
651
|
+
}
|
|
585
652
|
|
|
586
653
|
Peripheral peripheral = peripherals.get(deviceUUID);
|
|
587
654
|
if (peripheral == null) {
|
|
@@ -604,6 +671,19 @@ public class BleManager extends NativeBleManagerSpec {
|
|
|
604
671
|
callback.invoke("ServiceUUID, CharacteristicUUID and descriptorUUID required.", null);
|
|
605
672
|
return;
|
|
606
673
|
}
|
|
674
|
+
// Validate UUID formats to prevent crash
|
|
675
|
+
if (!UUIDHelper.isValidBLEUUID(serviceUUID)) {
|
|
676
|
+
callback.invoke("Invalid service UUID format: " + serviceUUID, null);
|
|
677
|
+
return;
|
|
678
|
+
}
|
|
679
|
+
if (!UUIDHelper.isValidBLEUUID(characteristicUUID)) {
|
|
680
|
+
callback.invoke("Invalid characteristic UUID format: " + characteristicUUID, null);
|
|
681
|
+
return;
|
|
682
|
+
}
|
|
683
|
+
if (!UUIDHelper.isValidBLEUUID(descriptorUUID)) {
|
|
684
|
+
callback.invoke("Invalid descriptor UUID format: " + descriptorUUID, null);
|
|
685
|
+
return;
|
|
686
|
+
}
|
|
607
687
|
|
|
608
688
|
Peripheral peripheral = peripherals.get(deviceUUID);
|
|
609
689
|
if (peripheral == null) {
|
|
@@ -109,9 +109,17 @@ public class CompanionScanner {
|
|
|
109
109
|
AssociationRequest.Builder builder = new AssociationRequest.Builder()
|
|
110
110
|
.setSingleDevice(options.hasKey("single") && options.getBoolean("single")) ;
|
|
111
111
|
|
|
112
|
+
int validUUIDCount = 0;
|
|
112
113
|
for (int i = 0; i < serviceUUIDs.size(); i++) {
|
|
113
|
-
|
|
114
|
+
String uuidString = serviceUUIDs.getString(i);
|
|
115
|
+
// Validate UUID format to prevent crash
|
|
116
|
+
if (!UUIDHelper.isValidBLEUUID(uuidString)) {
|
|
117
|
+
Log.w(LOG_TAG, "Warning: Invalid UUID format in scan options: " + uuidString + ", skipping");
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
final ParcelUuid uuid = new ParcelUuid(UUIDHelper.uuidFromString(uuidString));
|
|
114
121
|
Log.d(LOG_TAG, "Filter service: " + uuid);
|
|
122
|
+
validUUIDCount++;
|
|
115
123
|
|
|
116
124
|
builder = builder
|
|
117
125
|
// Add LE filter.
|
|
@@ -119,6 +127,12 @@ public class CompanionScanner {
|
|
|
119
127
|
.setScanFilter(new ScanFilter.Builder().setServiceUuid(uuid).build())
|
|
120
128
|
.build());
|
|
121
129
|
}
|
|
130
|
+
|
|
131
|
+
// If serviceUUIDs were provided but none were valid, return error
|
|
132
|
+
if (serviceUUIDs.size() > 0 && validUUIDCount == 0) {
|
|
133
|
+
callback.invoke("Invalid UUID format in serviceUUIDs: all UUIDs are invalid");
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
122
136
|
|
|
123
137
|
AssociationRequest pairingRequest = builder.build();
|
|
124
138
|
if (scanCallback != null) {
|
|
@@ -104,10 +104,23 @@ public class DefaultScanManager extends ScanManager {
|
|
|
104
104
|
|
|
105
105
|
ReadableArray serviceUUIDs = options.getArray("serviceUUIDs");
|
|
106
106
|
if (serviceUUIDs != null && serviceUUIDs.size() > 0) {
|
|
107
|
+
int validUUIDCount = 0;
|
|
107
108
|
for (int i = 0; i < serviceUUIDs.size(); i++) {
|
|
108
|
-
|
|
109
|
+
String uuidString = Objects.requireNonNull(serviceUUIDs.getString(i));
|
|
110
|
+
// Validate UUID format to prevent crash
|
|
111
|
+
if (!UUIDHelper.isValidBLEUUID(uuidString)) {
|
|
112
|
+
Log.w(BleManager.LOG_TAG, "Warning: Invalid UUID format in scan options: " + uuidString + ", skipping");
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
ScanFilter filter = new ScanFilter.Builder().setServiceUuid(new ParcelUuid(UUIDHelper.uuidFromString(uuidString))).build();
|
|
109
116
|
filters.add(filter);
|
|
110
|
-
|
|
117
|
+
validUUIDCount++;
|
|
118
|
+
Log.d(BleManager.LOG_TAG, "Filter service: " + uuidString);
|
|
119
|
+
}
|
|
120
|
+
// If serviceUUIDs were provided but none were valid, return error
|
|
121
|
+
if (validUUIDCount == 0) {
|
|
122
|
+
callback.invoke("Invalid UUID format in serviceUUIDs: all UUIDs are invalid");
|
|
123
|
+
return;
|
|
111
124
|
}
|
|
112
125
|
}
|
|
113
126
|
|
|
@@ -9,6 +9,27 @@ public class UUIDHelper {
|
|
|
9
9
|
// base UUID used to build 128 bit Bluetooth UUIDs
|
|
10
10
|
public static final String UUID_BASE = "0000XXXX-0000-1000-8000-00805f9b34fb";
|
|
11
11
|
|
|
12
|
+
// Validate BLE UUID format (16-bit or 128-bit)
|
|
13
|
+
// Returns true if the string is a valid BLE UUID format
|
|
14
|
+
public static boolean isValidBLEUUID(String uuidString) {
|
|
15
|
+
if (uuidString == null || uuidString.isEmpty()) {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// Validate 16-bit UUID (4 hex characters)
|
|
20
|
+
if (uuidString.length() == 4) {
|
|
21
|
+
return uuidString.matches("[0-9A-Fa-f]{4}");
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Validate 128-bit UUID (standard UUID format)
|
|
25
|
+
try {
|
|
26
|
+
UUID.fromString(uuidString);
|
|
27
|
+
return true;
|
|
28
|
+
} catch (IllegalArgumentException e) {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
12
33
|
// handle 16 and 128 bit UUIDs
|
|
13
34
|
public static UUID uuidFromString(String uuid) {
|
|
14
35
|
|
package/ios/Helper.swift
CHANGED
|
@@ -274,6 +274,24 @@ class Helper {
|
|
|
274
274
|
return nil // Characteristic not found on this service
|
|
275
275
|
}
|
|
276
276
|
|
|
277
|
+
// Validate BLE UUID format (16-bit or 128-bit)
|
|
278
|
+
// Returns true if the string is a valid BLE UUID format
|
|
279
|
+
static func isValidBLEUUID(_ uuidString: String) -> Bool {
|
|
280
|
+
// Check for empty string
|
|
281
|
+
if uuidString.isEmpty {
|
|
282
|
+
return false
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
// Validate 16-bit UUID (4 hex characters)
|
|
286
|
+
let hexCharacterSet = CharacterSet(charactersIn: "0123456789ABCDEFabcdef")
|
|
287
|
+
let isValid16Bit = uuidString.count == 4 && uuidString.rangeOfCharacter(from: hexCharacterSet.inverted) == nil
|
|
288
|
+
|
|
289
|
+
// Validate 128-bit UUID (standard UUID format)
|
|
290
|
+
let isValid128Bit = UUID(uuidString: uuidString) != nil
|
|
291
|
+
|
|
292
|
+
return isValid16Bit || isValid128Bit
|
|
293
|
+
}
|
|
294
|
+
|
|
277
295
|
}
|
|
278
296
|
|
|
279
297
|
class Peripheral: Hashable {
|
|
@@ -32,6 +32,15 @@ public class SwiftBleManager: NSObject, CBCentralManagerDelegate,
|
|
|
32
32
|
|
|
33
33
|
private let serialQueue = DispatchQueue(label: "BleManager.serialQueue")
|
|
34
34
|
|
|
35
|
+
// Structured error payload so JS can detect specific failures by (domain, code).
|
|
36
|
+
private static func errorPayload(_ error: Error) -> [String: Any] {
|
|
37
|
+
return [
|
|
38
|
+
"code": error._code,
|
|
39
|
+
"domain": error._domain,
|
|
40
|
+
"message": error.localizedDescription,
|
|
41
|
+
]
|
|
42
|
+
}
|
|
43
|
+
|
|
35
44
|
private var exactAdvertisingName: [String]
|
|
36
45
|
|
|
37
46
|
static var verboseLogging = false
|
|
@@ -191,6 +200,21 @@ public class SwiftBleManager: NSObject, CBCentralManagerDelegate,
|
|
|
191
200
|
prop: CBCharacteristicProperties,
|
|
192
201
|
callback: @escaping RCTResponseSenderBlock
|
|
193
202
|
) -> BLECommandContext? {
|
|
203
|
+
// Validate UUID formats to prevent CBUUID(string:) crash
|
|
204
|
+
guard Helper.isValidBLEUUID(serviceUUIDString) else {
|
|
205
|
+
let error = "Invalid service UUID format: \(serviceUUIDString)"
|
|
206
|
+
NSLog(error)
|
|
207
|
+
callback([error])
|
|
208
|
+
return nil
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
guard Helper.isValidBLEUUID(characteristicUUIDString) else {
|
|
212
|
+
let error = "Invalid characteristic UUID format: \(characteristicUUIDString)"
|
|
213
|
+
NSLog(error)
|
|
214
|
+
callback([error])
|
|
215
|
+
return nil
|
|
216
|
+
}
|
|
217
|
+
|
|
194
218
|
let serviceUUID = CBUUID(string: serviceUUIDString)
|
|
195
219
|
let characteristicUUID = CBUUID(string: characteristicUUIDString)
|
|
196
220
|
|
|
@@ -363,7 +387,21 @@ public class SwiftBleManager: NSObject, CBCentralManagerDelegate,
|
|
|
363
387
|
if let serviceUUIDStrings = scanningOptions["serviceUUIDs"]
|
|
364
388
|
as? [String]
|
|
365
389
|
{
|
|
366
|
-
|
|
390
|
+
// Validate UUID formats to prevent CBUUID(string:) crash
|
|
391
|
+
for uuidString in serviceUUIDStrings {
|
|
392
|
+
if Helper.isValidBLEUUID(uuidString) {
|
|
393
|
+
serviceUUIDs.append(CBUUID(string: uuidString))
|
|
394
|
+
} else {
|
|
395
|
+
NSLog("Warning: Invalid UUID format in scan options: \(uuidString), skipping")
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
// If serviceUUIDs were provided but none were valid, return error
|
|
399
|
+
if !serviceUUIDStrings.isEmpty && serviceUUIDs.isEmpty {
|
|
400
|
+
let error = "Invalid UUID format in serviceUUIDs: all UUIDs are invalid"
|
|
401
|
+
NSLog(error)
|
|
402
|
+
callback([error])
|
|
403
|
+
return
|
|
404
|
+
}
|
|
367
405
|
}
|
|
368
406
|
|
|
369
407
|
var options: [String: Any]?
|
|
@@ -528,8 +566,14 @@ public class SwiftBleManager: NSObject, CBCentralManagerDelegate,
|
|
|
528
566
|
|
|
529
567
|
var uuids: [CBUUID] = []
|
|
530
568
|
for string in services {
|
|
531
|
-
|
|
532
|
-
|
|
569
|
+
// Validate UUID format to prevent CBUUID(string:) crash
|
|
570
|
+
guard Helper.isValidBLEUUID(string) else {
|
|
571
|
+
let error = "Invalid service UUID format: \(string)"
|
|
572
|
+
NSLog(error)
|
|
573
|
+
callback([error])
|
|
574
|
+
return
|
|
575
|
+
}
|
|
576
|
+
uuids.append(CBUUID(string: string))
|
|
533
577
|
}
|
|
534
578
|
|
|
535
579
|
if !uuids.isEmpty {
|
|
@@ -587,6 +631,14 @@ public class SwiftBleManager: NSObject, CBCentralManagerDelegate,
|
|
|
587
631
|
let peripheral = context.peripheral
|
|
588
632
|
let characteristic = context.characteristic
|
|
589
633
|
|
|
634
|
+
// Validate UUID format to prevent CBUUID(string:) crash
|
|
635
|
+
guard Helper.isValidBLEUUID(descriptorUUID) else {
|
|
636
|
+
let error = "Invalid descriptor UUID format: \(descriptorUUID)"
|
|
637
|
+
NSLog(error)
|
|
638
|
+
callback([error])
|
|
639
|
+
return
|
|
640
|
+
}
|
|
641
|
+
|
|
590
642
|
guard
|
|
591
643
|
let descriptor = Helper.findDescriptor(
|
|
592
644
|
fromUUID: CBUUID(string: descriptorUUID),
|
|
@@ -642,6 +694,14 @@ public class SwiftBleManager: NSObject, CBCentralManagerDelegate,
|
|
|
642
694
|
let peripheral = context.peripheral
|
|
643
695
|
let characteristic = context.characteristic
|
|
644
696
|
|
|
697
|
+
// Validate UUID format to prevent CBUUID(string:) crash
|
|
698
|
+
guard Helper.isValidBLEUUID(descriptorUUID) else {
|
|
699
|
+
let error = "Invalid descriptor UUID format: \(descriptorUUID)"
|
|
700
|
+
NSLog(error)
|
|
701
|
+
callback([error])
|
|
702
|
+
return
|
|
703
|
+
}
|
|
704
|
+
|
|
645
705
|
guard
|
|
646
706
|
let descriptor = Helper.findDescriptor(
|
|
647
707
|
fromUUID: CBUUID(string: descriptorUUID),
|
|
@@ -696,6 +756,15 @@ public class SwiftBleManager: NSObject, CBCentralManagerDelegate,
|
|
|
696
756
|
var serviceUUIDs: [CBUUID] = []
|
|
697
757
|
|
|
698
758
|
for uuidString in serviceUUIDStrings {
|
|
759
|
+
// Validate BLE UUID format to prevent CBUUID(string:) crash
|
|
760
|
+
guard Helper.isValidBLEUUID(uuidString) else {
|
|
761
|
+
let error = uuidString.isEmpty ? "Invalid UUID: empty string" : "Invalid UUID format: \(uuidString)"
|
|
762
|
+
NSLog(error)
|
|
763
|
+
callback([error])
|
|
764
|
+
return
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
// Create CBUUID only with validated UUID string (prevents crash)
|
|
699
768
|
serviceUUIDs.append(CBUUID(string: uuidString))
|
|
700
769
|
}
|
|
701
770
|
|
|
@@ -1181,14 +1250,17 @@ public class SwiftBleManager: NSObject, CBCentralManagerDelegate,
|
|
|
1181
1250
|
didFailToConnect peripheral: CBPeripheral,
|
|
1182
1251
|
error: Error?
|
|
1183
1252
|
) {
|
|
1184
|
-
|
|
1253
|
+
NSLog(
|
|
1185
1254
|
"Peripheral connection failure: \(peripheral.uuidAsString() ) (\(error?.localizedDescription ?? "")"
|
|
1186
|
-
|
|
1255
|
+
)
|
|
1187
1256
|
|
|
1257
|
+
let errorParam: Any =
|
|
1258
|
+
error.map(SwiftBleManager.errorPayload)
|
|
1259
|
+
?? "Peripheral connection failure: \(peripheral.uuidAsString())"
|
|
1188
1260
|
invokeAndClearDictionary(
|
|
1189
1261
|
&connectCallbacks,
|
|
1190
1262
|
withKey: peripheral.uuidAsString(),
|
|
1191
|
-
usingParameters: [
|
|
1263
|
+
usingParameters: [errorParam]
|
|
1192
1264
|
)
|
|
1193
1265
|
}
|
|
1194
1266
|
|
|
@@ -1397,6 +1469,11 @@ public class SwiftBleManager: NSObject, CBCentralManagerDelegate,
|
|
|
1397
1469
|
) {
|
|
1398
1470
|
if let error = error {
|
|
1399
1471
|
NSLog("Error: \(error)")
|
|
1472
|
+
invokeAndClearDictionary(
|
|
1473
|
+
&retrieveServicesCallbacks,
|
|
1474
|
+
withKey: peripheral.uuidAsString(),
|
|
1475
|
+
usingParameters: [SwiftBleManager.errorPayload(error)]
|
|
1476
|
+
)
|
|
1400
1477
|
return
|
|
1401
1478
|
}
|
|
1402
1479
|
if SwiftBleManager.verboseLogging {
|
|
@@ -1440,21 +1517,44 @@ public class SwiftBleManager: NSObject, CBCentralManagerDelegate,
|
|
|
1440
1517
|
) {
|
|
1441
1518
|
if let error = error {
|
|
1442
1519
|
NSLog("Error: \(error)")
|
|
1443
|
-
return
|
|
1444
1520
|
}
|
|
1445
1521
|
if SwiftBleManager.verboseLogging {
|
|
1446
1522
|
NSLog("Characteristics For Service Discover")
|
|
1447
1523
|
}
|
|
1448
1524
|
|
|
1525
|
+
let peripheralUUIDString = peripheral.uuidAsString()
|
|
1526
|
+
let characteristics = (error == nil) ? (service.characteristics ?? []) : []
|
|
1527
|
+
|
|
1528
|
+
if characteristics.isEmpty {
|
|
1529
|
+
if var servicesLatch = retrieveServicesLatches[peripheralUUIDString] {
|
|
1530
|
+
servicesLatch.remove(service)
|
|
1531
|
+
retrieveServicesLatches[peripheralUUIDString] = servicesLatch
|
|
1532
|
+
|
|
1533
|
+
if servicesLatch.isEmpty {
|
|
1534
|
+
if let peripheral = peripherals[peripheralUUIDString] {
|
|
1535
|
+
invokeAndClearDictionary(
|
|
1536
|
+
&retrieveServicesCallbacks,
|
|
1537
|
+
withKey: peripheralUUIDString,
|
|
1538
|
+
usingParameters: [
|
|
1539
|
+
NSNull(), peripheral.servicesInfo(),
|
|
1540
|
+
]
|
|
1541
|
+
)
|
|
1542
|
+
}
|
|
1543
|
+
retrieveServicesLatches.removeValue(
|
|
1544
|
+
forKey: peripheralUUIDString
|
|
1545
|
+
)
|
|
1546
|
+
}
|
|
1547
|
+
}
|
|
1548
|
+
return
|
|
1549
|
+
}
|
|
1550
|
+
|
|
1449
1551
|
var characteristicsForService = Set<CBCharacteristic>()
|
|
1450
|
-
characteristicsForService.formUnion(
|
|
1552
|
+
characteristicsForService.formUnion(characteristics)
|
|
1451
1553
|
characteristicsLatches[service.uuid.uuidString] =
|
|
1452
1554
|
characteristicsForService
|
|
1453
1555
|
|
|
1454
|
-
|
|
1455
|
-
for characteristic
|
|
1456
|
-
peripheral.discoverDescriptors(for: characteristic)
|
|
1457
|
-
}
|
|
1556
|
+
for characteristic in characteristics {
|
|
1557
|
+
peripheral.discoverDescriptors(for: characteristic)
|
|
1458
1558
|
}
|
|
1459
1559
|
}
|
|
1460
1560
|
|
|
@@ -1465,7 +1565,6 @@ public class SwiftBleManager: NSObject, CBCentralManagerDelegate,
|
|
|
1465
1565
|
) {
|
|
1466
1566
|
if let error = error {
|
|
1467
1567
|
NSLog("Error: \(error)")
|
|
1468
|
-
return
|
|
1469
1568
|
}
|
|
1470
1569
|
let peripheralUUIDString: String = peripheral.uuidAsString()
|
|
1471
1570
|
let serviceUUIDString: String =
|
|
@@ -1525,7 +1624,7 @@ public class SwiftBleManager: NSObject, CBCentralManagerDelegate,
|
|
|
1525
1624
|
invokeAndClearDictionary(
|
|
1526
1625
|
&readRSSICallbacks,
|
|
1527
1626
|
withKey: peripheral.uuidAsString(),
|
|
1528
|
-
usingParameters: [error
|
|
1627
|
+
usingParameters: [SwiftBleManager.errorPayload(error), RSSI]
|
|
1529
1628
|
)
|
|
1530
1629
|
} else {
|
|
1531
1630
|
invokeAndClearDictionary(
|
|
@@ -1554,7 +1653,7 @@ public class SwiftBleManager: NSObject, CBCentralManagerDelegate,
|
|
|
1554
1653
|
invokeAndClearDictionary(
|
|
1555
1654
|
&readDescriptorCallbacks,
|
|
1556
1655
|
withKey: key,
|
|
1557
|
-
usingParameters: [error
|
|
1656
|
+
usingParameters: [SwiftBleManager.errorPayload(error), NSNull()]
|
|
1558
1657
|
)
|
|
1559
1658
|
return
|
|
1560
1659
|
}
|
|
@@ -1636,7 +1735,7 @@ public class SwiftBleManager: NSObject, CBCentralManagerDelegate,
|
|
|
1636
1735
|
invokeAndClearDictionary(
|
|
1637
1736
|
&readCallbacks,
|
|
1638
1737
|
withKey: key,
|
|
1639
|
-
usingParameters: [error
|
|
1738
|
+
usingParameters: [SwiftBleManager.errorPayload(error), NSNull()]
|
|
1640
1739
|
)
|
|
1641
1740
|
return
|
|
1642
1741
|
}
|
|
@@ -1793,7 +1892,7 @@ public class SwiftBleManager: NSObject, CBCentralManagerDelegate,
|
|
|
1793
1892
|
invokeAndClearDictionary(
|
|
1794
1893
|
&writeDescriptorCallbacks,
|
|
1795
1894
|
withKey: key,
|
|
1796
|
-
usingParameters: [error
|
|
1895
|
+
usingParameters: [SwiftBleManager.errorPayload(error)]
|
|
1797
1896
|
)
|
|
1798
1897
|
} else {
|
|
1799
1898
|
invokeAndClearDictionary(
|
|
@@ -1824,7 +1923,7 @@ public class SwiftBleManager: NSObject, CBCentralManagerDelegate,
|
|
|
1824
1923
|
invokeAndClearDictionary(
|
|
1825
1924
|
&writeCallbacks,
|
|
1826
1925
|
withKey: key,
|
|
1827
|
-
usingParameters: [error
|
|
1926
|
+
usingParameters: [SwiftBleManager.errorPayload(error)]
|
|
1828
1927
|
)
|
|
1829
1928
|
serialQueue.sync {
|
|
1830
1929
|
writeQueues.removeValue(forKey: key)
|