Elsammak
Elsammak

Reputation: 1142

didDisconnectPeripheral called by itself

I've an application which should use CoreBluetooth to connect to varies devices at once. My issue here is that unexpected disconnections occur. Once I got connected to any peripheral the method

func centralManager(_ central: CBCentralManager, didDisconnectPeripheral peripheral: CBPeripheral, error: Error?) {

gets called by itself which means the device is disconnected. I walk through the documentation but found nothing useful. I know that BLE can be one-to-many so where is this issue coming from? I check answers in iOS BLE peripherals keep disconnecting immediately after discoverServices is called and I'm already holding CBPeripherals in an array but problem still exist.

example of outputs I got

Connect to <CBPeripheral: 0x15e85a80, identifier = 1BD21078-B2B7-1EE9-5BDC-324DEC7A1BD6, name = Mac mini, state = connected>

Connect to <CBPeripheral: 0x15d83b20, identifier = 6BA160A7-55E7-501D-F195-437CDCD2B558, name = Mac mini, state = connected>

Disconnect from <CBPeripheral: 0x15e85a80, identifier = 1BD21078-B2B7-1EE9-5BDC-324DEC7A1BD6, name = Mac mini, state = disconnected> Error Domain=CBErrorDomain Code=6 "The connection has timed out unexpectedly." UserInfo={NSLocalizedDescription=The connection has timed out unexpectedly.}

Upvotes: 3

Views: 2792

Answers (2)

Elsammak
Elsammak

Reputation: 1142

After a lot of search I found that connecting to multiple devices causes this issue. https://spin.atomicobject.com/2016/01/20/multiple-ble-devices-in-ios/

Upvotes: 1

Emil
Emil

Reputation: 18452

There are some different reasons a link gets disconnected. Either some side initiate the disconnection procedure. Error 6 "The connection has timed out unexpectedly" means the Bluetooth link lost the connection on the radio level, due to for example getting out of range or other kind of interference.

Upvotes: 1

Related Questions