Closed
Description
Hey,
The problem is that when the delegate call
centralManager(_:didDisconnectPeripheral:error:)
is handled, we would like to use it to automatically "reconnect" by calling
centralManager.connect(peripheral)
since attempts to connect to a peripheral don’t time out.
But it does not work, as after digging into the issue, the underlying CBPeripheral
s are stored by the CBMCentralManagerNative
which is removed on didDisconnectPeripheral
so when connect
is called it is blocked the if statement as the peripheral is no longer hold in the dictionary.
Potentially a quick fix could be:
func centralManager(_ central: CBCentralManager,
didDisconnectPeripheral peripheral: CBPeripheral,
error: Error?) {
manager.delegate?.centralManager(manager,
didDisconnectPeripheral: getPeripheral(peripheral),
error: error)
// Check if the error is present otherwise the disconnection was explicit
if error == nil {
removePeripheral(peripheral)
}
}
But I guess, the biggest issue is that CBPeripherals
are strongly hold by CBMCentralManagerNative
in overall.