fix(ble): discover all services then filter; some firmware rejects scoped discovery

When discoverServices is called with a specific UUID list, certain firmware
returns an empty service array even though the requested service exists on
the device. Match expo-duooomi-app's behavior (discoverAllServicesAndCharacteristics)
by passing nil and filtering in the delegate callback.

Also log discovered service UUIDs to aid future debugging.
This commit is contained in:
km2023
2026-05-06 11:43:06 +08:00
parent ca4a0869fc
commit f4a32bb7e8

View File

@@ -136,7 +136,9 @@ extension BleClient: CBCentralManagerDelegate {
connectTimeoutWork = nil
connectedPeripheral = peripheral
peripheral.delegate = self
peripheral.discoverServices([BleUUIDs.service])
// service expo discoverAllServicesAndCharacteristics
// UUID didDiscoverServices
peripheral.discoverServices(nil)
}
func centralManager(_ central: CBCentralManager, didFailToConnect peripheral: CBPeripheral, error: Error?) {
@@ -177,7 +179,9 @@ extension BleClient: CBPeripheralDelegate {
cb?(.failure(error))
return
}
guard let service = peripheral.services?.first(where: { $0.uuid == BleUUIDs.service }) else {
let services = peripheral.services ?? []
BleLog.d("Discovered \(services.count) service(s): \(services.map { $0.uuid.uuidString })", "BLE")
guard let service = services.first(where: { $0.uuid == BleUUIDs.service }) else {
let cb = connectCompletion
connectCompletion = nil
cb?(.failure(DuooomiBleError.serviceNotFound))