3

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.}

Community
  • 1
  • 1
Elsammak
  • 1,102
  • 10
  • 26
  • 1
    Is the `error` parameter nil in your case? – Larme Apr 25 '17 at 14:49
  • Error Domain=CBErrorDomain Code=7 "The specified device has disconnected from us." UserInfo={NSLocalizedDescription=The specified device has disconnected from us.} – Elsammak Apr 26 '17 at 07:32
  • Are you connecting to always the sale kind of device? You can't keep connected to even 1 device? – Larme Apr 26 '17 at 07:34
  • That's happened between iOS devices (iPhone to iPad and vice versa). – Elsammak Apr 26 '17 at 07:38
  • So one device is only a Central, and the other only a Peripheral? Could you issue be on the code of your Peripheral? – Larme Apr 26 '17 at 08:00
  • I don't have a code written on my peripheral, I just has a code on my master device to connect to ant BT device. – Elsammak Apr 26 '17 at 08:02
  • I don't understand. Do you use an already all written app to be your peripheral? – Larme Apr 26 '17 at 08:30
  • No, I'm just having a simple iOS app which discover nearby devices and connect to them whatever their type is. – Elsammak Apr 26 '17 at 08:42
  • How many devices are you connecting to at one time? I read somewhere that the limit is small – bobwki Apr 26 '17 at 22:04

2 Answers2

1

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.

Emil
  • 16,784
  • 2
  • 41
  • 52
1

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/

Elsammak
  • 1,102
  • 10
  • 26