0

I try to reconnect my peripheral after rebooting the phone.

I'm using the location update callback to start the BLE connection process in background. The ble stack is correctly initialized in background (CBCentralManagerStatePoweredOn event sent)

The "connect" on the peripheral is started but no connection is established...

Any idea to reconnect a device after reboot ?

anticafe
  • 6,816
  • 9
  • 43
  • 74
fvisticot
  • 7,936
  • 14
  • 49
  • 79

1 Answers1

0

When you say that the "connect" on the peripheral is started, do you mean that you manually connect using connectPeripheral: ? I have in the past struggled with connection on iOS and noticed that CoreBluetooth has a lot of race conditions internally that you have to avoid. Typically what I recommend is to always do a dispatch delay on all connect requests of at lest 20ms that happens after a CoreBluetooth callback. This will avoid most race conditions. You can test this out yourself for example by setting a pending connection and then at a later point calling cancelPeripheralConnection: before the peripheral has connected. When you get the didFailToConnect callback then immediately call connectPeripheral: again. Now the connection should be in a "limbo" mode where the connection status is "connecting" but in fact the peripheral will never connect. Calling connect again will do nothing either at this point.

I don't know if this is the cause of your issue, but it could be. Also, upon CentralManager state restoration I would recommend letting the framework "settle" for around a second before starting interacting with it.

One other important thing is that you don't re-initiate the manager until after you get the applicationDidFinishLaunchingWithOptions: callback of your AppDelegate. Doing this earlier can cause strange behaviors.

Please do some more investigations and if you are still having issues then let me know. I may have some further tips. /Anton

Anton
  • 978
  • 8
  • 16