Skip to content

Commit

Permalink
Do not normalize UUIDs on native side (#138)
Browse files Browse the repository at this point in the history
  • Loading branch information
fotiDim authored Feb 16, 2025
1 parent 6013518 commit 1525628
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 25 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## 0.16.0
* Bump bluez to 0.8.3
* Improve readme
* Do not normalize UUIDs on native side
* Reverse _permissionStatus return values in example app

## 0.15.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,8 @@ fun Int.toBleConnectionState(): BleConnectionState {
}
}

fun String.validFullUUID(): String {
return when (this.count()) {
4 -> "0000$this-0000-1000-8000-00805F9B34FB"
8 -> "$this-0000-1000-8000-00805F9B34FB"
else -> this
}
}

fun List<String>.toUUIDList(): List<UUID> {
return this.map { UUID.fromString(it.validFullUUID()) }
return this.map { UUID.fromString(it) }
}


Expand Down
14 changes: 0 additions & 14 deletions darwin/Classes/UniversalBleHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -143,20 +143,6 @@ public extension CBPeripheral {
}
}

extension String {
var validFullUUID: String {
let uuidLength = count
if uuidLength == 4 || uuidLength == 8 {
let baseUuid = "00000000-0000-1000-8000-00805F9B34FB"
let start = baseUuid.startIndex
let range = baseUuid.index(start, offsetBy: 4 - uuidLength) ..< baseUuid.index(start, offsetBy: 4)
return baseUuid.replacingCharacters(in: range, with: self).lowercased()
} else {
return self
}
}
}

extension FlutterStandardTypedData {
func toData() -> Data {
return Data(data)
Expand Down
4 changes: 2 additions & 2 deletions darwin/Classes/UniversalBlePlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ private class BleCentralDarwin: NSObject, UniversalBlePlatformChannel, CBCentral
isPaired: nil,
rssi: RSSI as? Int64,
manufacturerDataList: manufacturerDataList,
services: services?.map { $0.uuidStr.validFullUUID }
services: services?.map { $0.uuidStr }
)) { _ in }
}

Expand Down Expand Up @@ -492,7 +492,7 @@ extension String {
extension [String] {
func toCBUUID() throws -> [CBUUID] {
return try compactMap { serviceUUID in
guard UUID(uuidString: serviceUUID.validFullUUID) != nil else {
guard UUID(uuidString: serviceUUID) != nil else {
throw PigeonError(code: "IllegalArgument", message: "Invalid service UUID:\(serviceUUID)", details: nil)
}
return CBUUID(string: serviceUUID)
Expand Down

0 comments on commit 1525628

Please sign in to comment.