Refactor service discovery to always perform fresh discovery, removing cached services check
Pull Request / test (push) Waiting to run
Pull Request / pana (push) Waiting to run

Signed-off-by: Tony <tonylu@tony-cloud.com>
This commit is contained in:
Tony
2026-08-08 08:41:43 +08:00
parent 52712055f5
commit 511f1fff5b
@@ -35,12 +35,11 @@ class UniversalBleAsyncServiceDiscovery: NSObject {
}
isDiscoveryInProgress = true
// Check if services are already cached
if let cachedServices = peripheral.services, !cachedServices.isEmpty {
handleServicesDiscovered(cachedServices)
} else {
peripheral.discoverServices(nil)
}
// A peripheral can keep CoreBluetooth's previous GATT view across a
// firmware update. UniversalBle.discoverServices is the explicit fresh
// discovery API; callers that want cached data use BleDevice's
// preferCached path instead.
peripheral.discoverServices(nil)
}
/// Cleans up discovery state
@@ -64,13 +63,7 @@ class UniversalBleAsyncServiceDiscovery: NSObject {
// Discover characteristics for each service
for service in services {
if let cachedChar = service.characteristics, !cachedChar.isEmpty {
// Characteristics already cached, process them
processCharacteristicsForService(service)
} else {
// Need to discover characteristics
peripheral.discoverCharacteristics(nil, for: service)
}
peripheral.discoverCharacteristics(nil, for: service)
}
}