Refactor service discovery to always perform fresh discovery, removing cached services check
Signed-off-by: Tony <tonylu@tony-cloud.com>
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user