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
|
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)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user