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 isDiscoveryInProgress = true
// Check if services are already cached // A peripheral can keep CoreBluetooth's previous GATT view across a
if let cachedServices = peripheral.services, !cachedServices.isEmpty { // firmware update. UniversalBle.discoverServices is the explicit fresh
handleServicesDiscovered(cachedServices) // discovery API; callers that want cached data use BleDevice's
} else { // preferCached path instead.
peripheral.discoverServices(nil) peripheral.discoverServices(nil)
}
} }
/// Cleans up discovery state /// Cleans up discovery state
@@ -64,13 +63,7 @@ class UniversalBleAsyncServiceDiscovery: NSObject {
// Discover characteristics for each service // Discover characteristics for each service
for service in services { for service in services {
if let cachedChar = service.characteristics, !cachedChar.isEmpty { peripheral.discoverCharacteristics(nil, for: service)
// Characteristics already cached, process them
processCharacteristicsForService(service)
} else {
// Need to discover characteristics
peripheral.discoverCharacteristics(nil, for: service)
}
} }
} }