munim-bluetooth 0.4.1 → 0.4.2

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.
@@ -1328,17 +1328,20 @@ class HybridMunimBluetooth: HybridMunimBluetoothSpec {
1328
1328
 
1329
1329
  private func hexStringToData(_ hex: String) -> Data? {
1330
1330
  var data = Data()
1331
- var hex = hex
1331
+ var hex = hex.trimmingCharacters(in: .whitespacesAndNewlines)
1332
1332
 
1333
1333
  if hex.count % 2 != 0 {
1334
1334
  hex = "0" + hex
1335
1335
  }
1336
1336
 
1337
- let regex = try! NSRegularExpression(pattern: "[0-9a-f]{1,2}", options: .caseInsensitive)
1338
- regex.enumerateMatches(in: hex, range: NSRange(hex.startIndex..., in: hex)) { match, _, _ in
1339
- let byteStr = (hex as NSString).substring(with: match!.range)
1340
- let num = UInt8(byteStr, radix: 16)!
1341
- data.append(num)
1337
+ var index = hex.startIndex
1338
+ while index < hex.endIndex {
1339
+ let nextIndex = hex.index(index, offsetBy: 2)
1340
+ guard let byte = UInt8(hex[index..<nextIndex], radix: 16) else {
1341
+ return nil
1342
+ }
1343
+ data.append(byte)
1344
+ index = nextIndex
1342
1345
  }
1343
1346
 
1344
1347
  return data.isEmpty ? nil : data
@@ -1525,13 +1528,13 @@ class HybridMunimBluetooth: HybridMunimBluetoothSpec {
1525
1528
  advertisingData[CBAdvertisementDataLocalNameKey] = localName
1526
1529
  }
1527
1530
 
1528
- let serviceUUIDs =
1529
- (data.incompleteServiceUUIDs16 ?? []) +
1530
- (data.completeServiceUUIDs16 ?? []) +
1531
- (data.incompleteServiceUUIDs32 ?? []) +
1532
- (data.completeServiceUUIDs32 ?? []) +
1533
- (data.incompleteServiceUUIDs128 ?? []) +
1534
- (data.completeServiceUUIDs128 ?? [])
1531
+ var serviceUUIDs: [String] = []
1532
+ serviceUUIDs.append(contentsOf: data.incompleteServiceUUIDs16 ?? [])
1533
+ serviceUUIDs.append(contentsOf: data.completeServiceUUIDs16 ?? [])
1534
+ serviceUUIDs.append(contentsOf: data.incompleteServiceUUIDs32 ?? [])
1535
+ serviceUUIDs.append(contentsOf: data.completeServiceUUIDs32 ?? [])
1536
+ serviceUUIDs.append(contentsOf: data.incompleteServiceUUIDs128 ?? [])
1537
+ serviceUUIDs.append(contentsOf: data.completeServiceUUIDs128 ?? [])
1535
1538
 
1536
1539
  if !serviceUUIDs.isEmpty {
1537
1540
  advertisingData[CBAdvertisementDataServiceUUIDsKey] = serviceUUIDs.map { CBUUID(string: $0) }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "munim-bluetooth",
3
- "version": "0.4.1",
3
+ "version": "0.4.2",
4
4
  "description": "A comprehensive React Native Bluetooth library for BLE central/peripheral, Android Classic Bluetooth, LE L2CAP, Apple Multipeer Connectivity, and Expo support",
5
5
  "main": "./lib/commonjs/index.js",
6
6
  "module": "./lib/module/index.js",