react-native-ble-manager 12.4.3 → 12.4.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.
@@ -1,6 +1,6 @@
1
1
  /**
2
- * android states: https://developer.android.com/reference/android/bluetooth/BluetoothAdapter#EXTRA_STATE
3
- * ios states: https://developer.apple.com/documentation/corebluetooth/cbcentralmanagerstate
2
+ * Android states: https://developer.android.com/reference/android/bluetooth/BluetoothAdapter#EXTRA_STATE
3
+ * iOS states: https://developer.apple.com/documentation/corebluetooth/cbcentralmanagerstate
4
4
  * */
5
5
  export declare enum BleState {
6
6
  /**
@@ -19,11 +19,11 @@ export declare enum BleState {
19
19
  On = "on",
20
20
  Off = "off",
21
21
  /**
22
- * [android only]
22
+ * [Android only]
23
23
  */
24
24
  TurningOn = "turning_on",
25
25
  /**
26
- * [android only]
26
+ * [Android only]
27
27
  */
28
28
  TurningOff = "turning_off"
29
29
  }
@@ -57,59 +57,82 @@ export interface CustomAdvertisingData {
57
57
  }
58
58
  export interface StartOptions {
59
59
  /**
60
- * [iOS only]
60
+ * [iOS only] Show or hide the alert if the bluetooth is turned off during initialization
61
61
  */
62
62
  showAlert?: boolean;
63
63
  /**
64
- * [iOS only]
64
+ * [iOS only] Unique key to use for CoreBluetooth state restoration
65
65
  */
66
66
  restoreIdentifierKey?: string;
67
67
  /**
68
- * [iOS only]
68
+ * [iOS only] Unique key to use for a queue identifier on which CoreBluetooth events will be dispatched
69
69
  */
70
70
  queueIdentifierKey?: string;
71
71
  /**
72
- * [android only]
72
+ * [Android only] Force to use the LegacyScanManager
73
73
  */
74
74
  forceLegacy?: boolean;
75
75
  }
76
76
  export interface ConnectOptions {
77
77
  /**
78
- * [android only]
78
+ * [Android only] whether to directly connect to the remote device (false) or to automatically connect as soon as the remote device becomes available (true) ([`Android doc`](<https://developer.android.com/reference/android/bluetooth/BluetoothDevice?hl=en#connectGatt(android.content.Context,%20boolean,%20android.bluetooth.BluetoothGattCallback,%20int,%20int)>))
79
79
  */
80
80
  autoconnect?: boolean;
81
81
  /**
82
- * [android only]
82
+ * [Android only] corresponding to the preferred phy channel ([`Android doc`](<https://developer.android.com/reference/android/bluetooth/BluetoothDevice?hl=en#connectGatt(android.content.Context,%20boolean,%20android.bluetooth.BluetoothGattCallback,%20int,%20int)>))
83
83
  */
84
84
  phy?: BleScanPhyMode;
85
85
  }
86
86
  /**
87
- * [android only]
87
+ * [Android only]
88
88
  * https://developer.android.com/reference/android/bluetooth/le/ScanSettings
89
89
  */
90
90
  export interface ScanOptions {
91
+ /**
92
+ * The UUIDs of the services to look for.
93
+ */
91
94
  serviceUUIDs?: string[];
95
+ /**
96
+ * The amount of seconds to scan. If not set or set to `0`, scans until `stopScan()` is called.
97
+ */
92
98
  seconds?: number;
93
99
  /**
94
- * iOS only: whether to allow duplicate peripheral during a scan
100
+ * In Android this is a ScanFilter, if present it restricts scan results to devices with a specific advertising name.
101
+ * This is a whole word match, not a partial search.
102
+ * Use with caution, it's behavior is tricky and seems to be the following:
103
+ * if `callbackType` is set to `AllMatches`, only the completeLocalName will be used for filtering.
104
+ * if `callbackType` is set to `FirstMatch`, the shortenedLocalName will be used for filtering.
105
+ * https://developer.android.com/reference/android/bluetooth/le/ScanFilter.Builder#setDeviceName(java.lang.String)
106
+ *
107
+ * In iOS, this is a whole word match, not a partial search.
108
+ */
109
+ exactAdvertisingName?: string | string[];
110
+ /**
111
+ * [iOS only] whether to allow duplicate peripheral during a scan
95
112
  */
96
113
  allowDuplicates?: boolean;
97
114
  /**
98
- * This will only works if a ScanFilter is active. Otherwise, may not retrieve any result.
115
+ * [Android only] This will only work if a ScanFilter is active. Otherwise, may not retrieve any result.
99
116
  * See https://developer.android.com/reference/android/bluetooth/le/ScanSettings#MATCH_NUM_FEW_ADVERTISEMENT.
100
117
  * */
101
118
  numberOfMatches?: BleScanMatchCount;
119
+ /**
120
+ * [Android only] Defaults to `aggressive`.
121
+ */
102
122
  matchMode?: BleScanMatchMode;
103
123
  /**
104
- * This will only works if a ScanFilter is active. Otherwise, may not retrieve any result.
124
+ * [Android only] This will only work if a ScanFilter is active. Otherwise, may not retrieve any result.
105
125
  * See https://developer.android.com/reference/android/bluetooth/le/ScanSettings#CALLBACK_TYPE_FIRST_MATCH.
106
126
  * Also read [this issue](https://github.com/dariuszseweryn/RxAndroidBle/issues/561#issuecomment-532295346) for a deeper understanding
107
- * of the very brittle stability of ScanSettings on android.
127
+ * of the very brittle stability of ScanSettings on Android. Defaults to `allMatches`.
108
128
  * */
109
129
  callbackType?: BleScanCallbackType;
130
+ /**
131
+ * [Android only] Defaults to `lowPower`.
132
+ */
110
133
  scanMode?: BleScanMode;
111
134
  /**
112
- * This is supposed to push results after a certain delay.
135
+ * [Android only] This is supposed to push results after a certain delay.
113
136
  * In practice it is tricky, use with caution.
114
137
  * Do not set something below 5000ms as it will wait that long anyway before pushing the first results,
115
138
  * or on some phones it will ignore that setting and behave just like it was set to 0.
@@ -118,29 +141,20 @@ export interface ScanOptions {
118
141
  */
119
142
  reportDelay?: number;
120
143
  /**
121
- * Does not work in conjunction with legacy scans. Setting an unsupported PHY will result in a failure to scan,
144
+ * [Android only] Does not work in conjunction with legacy scans. Setting an unsupported PHY will result in a failure to scan,
122
145
  * use with caution.
123
146
  * https://developer.android.com/reference/android/bluetooth/le/ScanSettings.Builder#setPhy(int)
124
147
  */
125
148
  phy?: BleScanPhyMode;
126
149
  /**
127
- * true by default for compatibility with older apps.
150
+ * [Android only] true by default for compatibility with older apps.
128
151
  * In that mode, scan will only retrieve advertisements data as specified by BLE 4.2 and below.
129
152
  * Change this if you want to benefit from the extended BLE 5 advertisement spec.
130
153
  * https://developer.android.com/reference/android/bluetooth/le/ScanSettings.Builder#setLegacy(boolean)
131
154
  */
132
155
  legacy?: boolean;
133
156
  /**
134
- * an android ScanFilter, used if present to restrict scan results to devices with a specific advertising name.
135
- * This is a whole word match, not a partial search.
136
- * Use with caution, it's behavior is tricky and seems to be the following:
137
- * if `callbackType` is set to `AllMatches`, only the completeLocalName will be used for filtering.
138
- * if `callbackType` is set to `FirstMatch`, the shortenedLocalName will be used for filtering.
139
- * https://developer.android.com/reference/android/bluetooth/le/ScanFilter.Builder#setDeviceName(java.lang.String)
140
- */
141
- exactAdvertisingName?: string | string[];
142
- /**
143
- * Android only. Filters scan results by manufacturer id and data.
157
+ * [Android only] Filters scan results by manufacturer id and data.
144
158
  * `manufacturerId` usually matches the company id, can be given as a hex, e.g. 0xe4f7.
145
159
  * `manufacturerData` and `manufacturerDataMask` must have the same length. For any bit in the mask, set it to 1 if
146
160
  * it needs to match the one in manufacturer data, otherwise set it to 0.
@@ -151,13 +165,6 @@ export interface ScanOptions {
151
165
  manufacturerData?: number[];
152
166
  manufacturerDataMask?: number[];
153
167
  };
154
- /**
155
- * When using compaion mode, only associate single peripheral.
156
- *
157
- * See: https://developer.android.com/reference/android/companion/AssociationRequest.Builder#setSingleDevice(boolean)
158
- */
159
- single?: boolean;
160
- companion?: boolean;
161
168
  /**
162
169
  * [Android O+] Deliver scan results using a PendingIntent instead of the default callback.
163
170
  */
@@ -165,12 +172,12 @@ export interface ScanOptions {
165
172
  }
166
173
  export interface CompanionScanOptions {
167
174
  /**
168
- * Scan only for a single peripheral.
175
+ * Scan only for a single peripheral. See Android's `AssociationRequest.Builder.setSingleDevice`.
169
176
  */
170
177
  single?: boolean;
171
178
  }
172
179
  /**
173
- * [android only]
180
+ * [Android only]
174
181
  */
175
182
  export declare enum BleScanMode {
176
183
  Opportunistic = -1,
@@ -179,14 +186,14 @@ export declare enum BleScanMode {
179
186
  LowLatency = 2
180
187
  }
181
188
  /**
182
- * [android only]
189
+ * [Android only]
183
190
  */
184
191
  export declare enum BleScanMatchMode {
185
192
  Aggressive = 1,
186
193
  Sticky = 2
187
194
  }
188
195
  /**
189
- * [android only]
196
+ * [Android only]
190
197
  */
191
198
  export declare enum BleScanCallbackType {
192
199
  AllMatches = 1,
@@ -194,7 +201,7 @@ export declare enum BleScanCallbackType {
194
201
  MatchLost = 4
195
202
  }
196
203
  /**
197
- * [android only]
204
+ * [Android only]
198
205
  */
199
206
  export declare enum BleScanMatchCount {
200
207
  OneAdvertisement = 1,
@@ -202,7 +209,7 @@ export declare enum BleScanMatchCount {
202
209
  MaxAdvertisements = 3
203
210
  }
204
211
  /**
205
- * [android only]
212
+ * [Android only]
206
213
  */
207
214
  export declare enum BleScanPhyMode {
208
215
  LE_1M = 1,
@@ -211,7 +218,7 @@ export declare enum BleScanPhyMode {
211
218
  ALL_SUPPORTED = 255
212
219
  }
213
220
  /**
214
- * [android only API 21+]
221
+ * [Android only API 21+]
215
222
  */
216
223
  export declare enum ConnectionPriority {
217
224
  balanced = 0,
@@ -250,34 +257,18 @@ export interface PeripheralInfo extends Peripheral {
250
257
  characteristics?: Characteristic[];
251
258
  services?: Service[];
252
259
  }
253
- export declare enum BleEventType {
254
- BleManagerDidUpdateState = "BleManagerDidUpdateState",
255
- BleManagerStopScan = "BleManagerStopScan",
256
- BleManagerDiscoverPeripheral = "BleManagerDiscoverPeripheral",
257
- BleManagerDidUpdateValueForCharacteristic = "BleManagerDidUpdateValueForCharacteristic",
258
- BleManagerConnectPeripheral = "BleManagerConnectPeripheral",
259
- BleManagerDisconnectPeripheral = "BleManagerDisconnectPeripheral",
260
- /**
261
- * [Android only]
262
- */
263
- BleManagerPeripheralDidBond = "BleManagerPeripheralDidBond",
264
- /**
265
- * [iOS only]
266
- */
267
- BleManagerCentralManagerWillRestoreState = "BleManagerCentralManagerWillRestoreState",
268
- /**
269
- * [iOS only]
270
- */
271
- BleManagerDidUpdateNotificationStateFor = "BleManagerDidUpdateNotificationStateFor"
272
- }
273
260
  export type EventCallback<T> = (event: T) => void | Promise<void>;
274
261
  export interface BleStopScanEvent {
275
262
  /**
276
- * [iOS only]
263
+ * [iOS] The reason for stopping the scan. Error code 10 is used for timeouts, 0 covers everything else.
264
+ * [Android] The reason for stopping the scan (<https://developer.android.com/reference/android/bluetooth/le/ScanCallback#constants_1>). Error code 10 is used for timeouts
277
265
  */
278
266
  status?: number;
279
267
  }
280
268
  export interface BleManagerDidUpdateStateEvent {
269
+ /**
270
+ * The new BLE state
271
+ */
281
272
  state: BleState;
282
273
  }
283
274
  export interface BleConnectPeripheralEvent {
@@ -286,7 +277,9 @@ export interface BleConnectPeripheralEvent {
286
277
  */
287
278
  readonly peripheral: string;
288
279
  /**
289
- * [android only]
280
+ * [Android only]
281
+ *
282
+ * Connect reason.
290
283
  */
291
284
  readonly status?: number;
292
285
  }
@@ -301,7 +294,7 @@ export interface BleDisconnectPeripheralEvent {
301
294
  */
302
295
  readonly peripheral: string;
303
296
  /**
304
- * [android only] disconnect reason.
297
+ * [Android only] disconnect reason.
305
298
  */
306
299
  readonly status?: number;
307
300
  /**
package/dist/esm/types.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /**
2
- * android states: https://developer.android.com/reference/android/bluetooth/BluetoothAdapter#EXTRA_STATE
3
- * ios states: https://developer.apple.com/documentation/corebluetooth/cbcentralmanagerstate
2
+ * Android states: https://developer.android.com/reference/android/bluetooth/BluetoothAdapter#EXTRA_STATE
3
+ * iOS states: https://developer.apple.com/documentation/corebluetooth/cbcentralmanagerstate
4
4
  * */
5
5
  export var BleState;
6
6
  (function (BleState) {
@@ -20,16 +20,16 @@ export var BleState;
20
20
  BleState["On"] = "on";
21
21
  BleState["Off"] = "off";
22
22
  /**
23
- * [android only]
23
+ * [Android only]
24
24
  */
25
25
  BleState["TurningOn"] = "turning_on";
26
26
  /**
27
- * [android only]
27
+ * [Android only]
28
28
  */
29
29
  BleState["TurningOff"] = "turning_off";
30
30
  })(BleState || (BleState = {}));
31
31
  /**
32
- * [android only]
32
+ * [Android only]
33
33
  */
34
34
  export var BleScanMode;
35
35
  (function (BleScanMode) {
@@ -39,7 +39,7 @@ export var BleScanMode;
39
39
  BleScanMode[BleScanMode["LowLatency"] = 2] = "LowLatency";
40
40
  })(BleScanMode || (BleScanMode = {}));
41
41
  /**
42
- * [android only]
42
+ * [Android only]
43
43
  */
44
44
  export var BleScanMatchMode;
45
45
  (function (BleScanMatchMode) {
@@ -47,7 +47,7 @@ export var BleScanMatchMode;
47
47
  BleScanMatchMode[BleScanMatchMode["Sticky"] = 2] = "Sticky";
48
48
  })(BleScanMatchMode || (BleScanMatchMode = {}));
49
49
  /**
50
- * [android only]
50
+ * [Android only]
51
51
  */
52
52
  export var BleScanCallbackType;
53
53
  (function (BleScanCallbackType) {
@@ -56,7 +56,7 @@ export var BleScanCallbackType;
56
56
  BleScanCallbackType[BleScanCallbackType["MatchLost"] = 4] = "MatchLost";
57
57
  })(BleScanCallbackType || (BleScanCallbackType = {}));
58
58
  /**
59
- * [android only]
59
+ * [Android only]
60
60
  */
61
61
  export var BleScanMatchCount;
62
62
  (function (BleScanMatchCount) {
@@ -65,7 +65,7 @@ export var BleScanMatchCount;
65
65
  BleScanMatchCount[BleScanMatchCount["MaxAdvertisements"] = 3] = "MaxAdvertisements";
66
66
  })(BleScanMatchCount || (BleScanMatchCount = {}));
67
67
  /**
68
- * [android only]
68
+ * [Android only]
69
69
  */
70
70
  export var BleScanPhyMode;
71
71
  (function (BleScanPhyMode) {
@@ -75,7 +75,7 @@ export var BleScanPhyMode;
75
75
  BleScanPhyMode[BleScanPhyMode["ALL_SUPPORTED"] = 255] = "ALL_SUPPORTED";
76
76
  })(BleScanPhyMode || (BleScanPhyMode = {}));
77
77
  /**
78
- * [android only API 21+]
78
+ * [Android only API 21+]
79
79
  */
80
80
  export var ConnectionPriority;
81
81
  (function (ConnectionPriority) {
@@ -83,25 +83,4 @@ export var ConnectionPriority;
83
83
  ConnectionPriority[ConnectionPriority["high"] = 1] = "high";
84
84
  ConnectionPriority[ConnectionPriority["low"] = 2] = "low";
85
85
  })(ConnectionPriority || (ConnectionPriority = {}));
86
- export var BleEventType;
87
- (function (BleEventType) {
88
- BleEventType["BleManagerDidUpdateState"] = "BleManagerDidUpdateState";
89
- BleEventType["BleManagerStopScan"] = "BleManagerStopScan";
90
- BleEventType["BleManagerDiscoverPeripheral"] = "BleManagerDiscoverPeripheral";
91
- BleEventType["BleManagerDidUpdateValueForCharacteristic"] = "BleManagerDidUpdateValueForCharacteristic";
92
- BleEventType["BleManagerConnectPeripheral"] = "BleManagerConnectPeripheral";
93
- BleEventType["BleManagerDisconnectPeripheral"] = "BleManagerDisconnectPeripheral";
94
- /**
95
- * [Android only]
96
- */
97
- BleEventType["BleManagerPeripheralDidBond"] = "BleManagerPeripheralDidBond";
98
- /**
99
- * [iOS only]
100
- */
101
- BleEventType["BleManagerCentralManagerWillRestoreState"] = "BleManagerCentralManagerWillRestoreState";
102
- /**
103
- * [iOS only]
104
- */
105
- BleEventType["BleManagerDidUpdateNotificationStateFor"] = "BleManagerDidUpdateNotificationStateFor";
106
- })(BleEventType || (BleEventType = {}));
107
86
  //# sourceMappingURL=types.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA;;;KAGK;AACL,MAAM,CAAN,IAAY,QAwBX;AAxBD,WAAY,QAAQ;IAClB;;OAEG;IACH,+BAAmB,CAAA;IACnB;;OAEG;IACH,mCAAuB,CAAA;IACvB,uCAA2B,CAAA;IAC3B;;OAEG;IACH,yCAA6B,CAAA;IAC7B,qBAAS,CAAA;IACT,uBAAW,CAAA;IACX;;OAEG;IACH,oCAAwB,CAAA;IACxB;;OAEG;IACH,sCAA0B,CAAA;AAC5B,CAAC,EAxBW,QAAQ,KAAR,QAAQ,QAwBnB;AAuJD;;GAEG;AACH,MAAM,CAAN,IAAY,WAKX;AALD,WAAY,WAAW;IACrB,gEAAkB,CAAA;IAClB,qDAAY,CAAA;IACZ,qDAAY,CAAA;IACZ,yDAAc,CAAA;AAChB,CAAC,EALW,WAAW,KAAX,WAAW,QAKtB;AAED;;GAEG;AACH,MAAM,CAAN,IAAY,gBAGX;AAHD,WAAY,gBAAgB;IAC1B,mEAAc,CAAA;IACd,2DAAU,CAAA;AACZ,CAAC,EAHW,gBAAgB,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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 {
@@ -191,6 +191,21 @@ public class SwiftBleManager: NSObject, CBCentralManagerDelegate,
191
191
  prop: CBCharacteristicProperties,
192
192
  callback: @escaping RCTResponseSenderBlock
193
193
  ) -> BLECommandContext? {
194
+ // Validate UUID formats to prevent CBUUID(string:) crash
195
+ guard Helper.isValidBLEUUID(serviceUUIDString) else {
196
+ let error = "Invalid service UUID format: \(serviceUUIDString)"
197
+ NSLog(error)
198
+ callback([error])
199
+ return nil
200
+ }
201
+
202
+ guard Helper.isValidBLEUUID(characteristicUUIDString) else {
203
+ let error = "Invalid characteristic UUID format: \(characteristicUUIDString)"
204
+ NSLog(error)
205
+ callback([error])
206
+ return nil
207
+ }
208
+
194
209
  let serviceUUID = CBUUID(string: serviceUUIDString)
195
210
  let characteristicUUID = CBUUID(string: characteristicUUIDString)
196
211
 
@@ -363,7 +378,21 @@ public class SwiftBleManager: NSObject, CBCentralManagerDelegate,
363
378
  if let serviceUUIDStrings = scanningOptions["serviceUUIDs"]
364
379
  as? [String]
365
380
  {
366
- serviceUUIDs = serviceUUIDStrings.map { CBUUID(string: $0) }
381
+ // Validate UUID formats to prevent CBUUID(string:) crash
382
+ for uuidString in serviceUUIDStrings {
383
+ if Helper.isValidBLEUUID(uuidString) {
384
+ serviceUUIDs.append(CBUUID(string: uuidString))
385
+ } else {
386
+ NSLog("Warning: Invalid UUID format in scan options: \(uuidString), skipping")
387
+ }
388
+ }
389
+ // If serviceUUIDs were provided but none were valid, return error
390
+ if !serviceUUIDStrings.isEmpty && serviceUUIDs.isEmpty {
391
+ let error = "Invalid UUID format in serviceUUIDs: all UUIDs are invalid"
392
+ NSLog(error)
393
+ callback([error])
394
+ return
395
+ }
367
396
  }
368
397
 
369
398
  var options: [String: Any]?
@@ -528,8 +557,14 @@ public class SwiftBleManager: NSObject, CBCentralManagerDelegate,
528
557
 
529
558
  var uuids: [CBUUID] = []
530
559
  for string in services {
531
- let uuid = CBUUID(string: string)
532
- uuids.append(uuid)
560
+ // Validate UUID format to prevent CBUUID(string:) crash
561
+ guard Helper.isValidBLEUUID(string) else {
562
+ let error = "Invalid service UUID format: \(string)"
563
+ NSLog(error)
564
+ callback([error])
565
+ return
566
+ }
567
+ uuids.append(CBUUID(string: string))
533
568
  }
534
569
 
535
570
  if !uuids.isEmpty {
@@ -587,6 +622,14 @@ public class SwiftBleManager: NSObject, CBCentralManagerDelegate,
587
622
  let peripheral = context.peripheral
588
623
  let characteristic = context.characteristic
589
624
 
625
+ // Validate UUID format to prevent CBUUID(string:) crash
626
+ guard Helper.isValidBLEUUID(descriptorUUID) else {
627
+ let error = "Invalid descriptor UUID format: \(descriptorUUID)"
628
+ NSLog(error)
629
+ callback([error])
630
+ return
631
+ }
632
+
590
633
  guard
591
634
  let descriptor = Helper.findDescriptor(
592
635
  fromUUID: CBUUID(string: descriptorUUID),
@@ -642,6 +685,14 @@ public class SwiftBleManager: NSObject, CBCentralManagerDelegate,
642
685
  let peripheral = context.peripheral
643
686
  let characteristic = context.characteristic
644
687
 
688
+ // Validate UUID format to prevent CBUUID(string:) crash
689
+ guard Helper.isValidBLEUUID(descriptorUUID) else {
690
+ let error = "Invalid descriptor UUID format: \(descriptorUUID)"
691
+ NSLog(error)
692
+ callback([error])
693
+ return
694
+ }
695
+
645
696
  guard
646
697
  let descriptor = Helper.findDescriptor(
647
698
  fromUUID: CBUUID(string: descriptorUUID),
@@ -696,6 +747,15 @@ public class SwiftBleManager: NSObject, CBCentralManagerDelegate,
696
747
  var serviceUUIDs: [CBUUID] = []
697
748
 
698
749
  for uuidString in serviceUUIDStrings {
750
+ // Validate BLE UUID format to prevent CBUUID(string:) crash
751
+ guard Helper.isValidBLEUUID(uuidString) else {
752
+ let error = uuidString.isEmpty ? "Invalid UUID: empty string" : "Invalid UUID format: \(uuidString)"
753
+ NSLog(error)
754
+ callback([error])
755
+ return
756
+ }
757
+
758
+ // Create CBUUID only with validated UUID string (prevents crash)
699
759
  serviceUUIDs.append(CBUUID(string: uuidString))
700
760
  }
701
761
 
@@ -1397,6 +1457,11 @@ public class SwiftBleManager: NSObject, CBCentralManagerDelegate,
1397
1457
  ) {
1398
1458
  if let error = error {
1399
1459
  NSLog("Error: \(error)")
1460
+ invokeAndClearDictionary(
1461
+ &retrieveServicesCallbacks,
1462
+ withKey: peripheral.uuidAsString(),
1463
+ usingParameters: [error.localizedDescription]
1464
+ )
1400
1465
  return
1401
1466
  }
1402
1467
  if SwiftBleManager.verboseLogging {
@@ -1440,21 +1505,44 @@ public class SwiftBleManager: NSObject, CBCentralManagerDelegate,
1440
1505
  ) {
1441
1506
  if let error = error {
1442
1507
  NSLog("Error: \(error)")
1443
- return
1444
1508
  }
1445
1509
  if SwiftBleManager.verboseLogging {
1446
1510
  NSLog("Characteristics For Service Discover")
1447
1511
  }
1448
1512
 
1513
+ let peripheralUUIDString = peripheral.uuidAsString()
1514
+ let characteristics = (error == nil) ? (service.characteristics ?? []) : []
1515
+
1516
+ if characteristics.isEmpty {
1517
+ if var servicesLatch = retrieveServicesLatches[peripheralUUIDString] {
1518
+ servicesLatch.remove(service)
1519
+ retrieveServicesLatches[peripheralUUIDString] = servicesLatch
1520
+
1521
+ if servicesLatch.isEmpty {
1522
+ if let peripheral = peripherals[peripheralUUIDString] {
1523
+ invokeAndClearDictionary(
1524
+ &retrieveServicesCallbacks,
1525
+ withKey: peripheralUUIDString,
1526
+ usingParameters: [
1527
+ NSNull(), peripheral.servicesInfo(),
1528
+ ]
1529
+ )
1530
+ }
1531
+ retrieveServicesLatches.removeValue(
1532
+ forKey: peripheralUUIDString
1533
+ )
1534
+ }
1535
+ }
1536
+ return
1537
+ }
1538
+
1449
1539
  var characteristicsForService = Set<CBCharacteristic>()
1450
- characteristicsForService.formUnion(service.characteristics ?? [])
1540
+ characteristicsForService.formUnion(characteristics)
1451
1541
  characteristicsLatches[service.uuid.uuidString] =
1452
1542
  characteristicsForService
1453
1543
 
1454
- if let characteristics = service.characteristics {
1455
- for characteristic in characteristics {
1456
- peripheral.discoverDescriptors(for: characteristic)
1457
- }
1544
+ for characteristic in characteristics {
1545
+ peripheral.discoverDescriptors(for: characteristic)
1458
1546
  }
1459
1547
  }
1460
1548
 
@@ -1465,7 +1553,6 @@ public class SwiftBleManager: NSObject, CBCentralManagerDelegate,
1465
1553
  ) {
1466
1554
  if let error = error {
1467
1555
  NSLog("Error: \(error)")
1468
- return
1469
1556
  }
1470
1557
  let peripheralUUIDString: String = peripheral.uuidAsString()
1471
1558
  let serviceUUIDString: String =
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-ble-manager",
3
- "version": "12.4.3",
3
+ "version": "12.4.5",
4
4
  "description": "A BLE module for react native.",
5
5
  "homepage": "https://innoveit.github.io/react-native-ble-manager/",
6
6
  "repository": {