Open romansavrulin opened 5 years ago
That is the way it is implemented. You can stop the scan anytime after you connect.
@troystribling But the scan is stopped right after discovery. Why the second scan attempt doesn't employ timeout?
@troystribling Quick follow-up sequence
Am I missing something?
Did not follow. That sounds like a bug. Start looking here. https://github.com/troystribling/BlueCap/blob/master/BlueCapKit/Central/CentralManager.swift#L212. The code is not that complicated. I do not have the time available now to look into this but will be will ing to accept a PR.
@troystribling Ok, thank you. Will dive into this, once we will be working on new maintenance release of our App
Quick try to fix the timeout inside the library wasn't successful, so I've worked-around this by the following code
func startDiscovery(uuid:String){
scanTimeoutTimer = Timer.scheduledTimer(withTimeInterval: 10.0, repeats: false) { _ in
log.info("Scan timeout has passed")
if self.manager.isScanning {
self.manager.stopScanning()
//trigger timeout event here
}
self.scanTimeoutTimer?.invalidate()
}
let discoveryFuture = manager.startScanning(forServiceUUIDs: [CBUUID(string:uuid)]).flatMap { peripheral -> FutureStream<Void> in
log.info("scanFuture: Found peripheral UUID: \(peripheral.identifier.uuidString). Trying to connect")
self.manager.stopScanning()
self.scanTimeoutTimer?.invalidate()
return peripheral.connect(connectionTimeout: 10, capacity: 1)
}
}
Bluecap from Carthage, version 0.7.0.
The following simple code
will successfully timeout scan for not available service for the first time. But if I will scan for the service that is available and connect to the device, the second scan attempt for unavailable service will never timeout.
Is it a Bluecap or Core Bluetooth issue?