Practical Causes of centralManager:didFailToConnectPeripheral:error:

Hi all, I was curious when the CBCentralManager delegate method "centralManager:didFailToConnectPeripheral:error:" is called. For reference the documentation for the method is below:

This method is invoked when a connection initiated via the connectPeripheral:options: method fails to complete. Because connection attempts do not time out, a failed connection usually indicates a transient issue, in which case you may attempt to connect to the peripheral again.

https://developer.apple.com/documentation/corebluetooth/cbcentralmanagerdelegate/1518988-centralmanager?language=objc


Could anyone elaborate on when this delegate method is invoked? In particular what are some of "transient" issues? Is there any sense of how often they occur? If the issue is "transient", how long is it expected to last? I've tried various scenarios to trigger this case but have never seen the method invoked.


Note: I'm investigating CoreBluetooth state restoration and preservation and want to make sure I am handling this case correctly. If any of these transient issues are more likely to occur in the background I'd be interested.

Accepted Answer

To answer my own question below is what I've found. The main take away is that

centralManager:didFailToConnectPeripheral:error:
is called rarely in iOS 11 and is exteremely rare in iOS 12.


iOS 11

Looking at more than 10,000 connection attempts events it appears that

centralManager:didFailToConnectPeripheral:error:
is called less than 1% of the time a connection is attempted. The error returned from CoreBluetooth is always the following:
Error Domain=CBErrorDomain Code=0 "Unknown error." UserInfo={NSLocalizedDescription=Unknown error.}


iOS 12

Looking at more than 10,000 connection attempts events it appears that

centralManager:didFailToConnectPeripheral:error:
is called 0.002% of the time a connection is attempted. It looks like changes were made to CoreBluetooth in iOS 12 that have fixed the source of most these errors. When it does occur, two different errors have been observed:
  • 90% of the time the error is:
    Error Domain=CBInternalErrorDomain Code=12 "Device is invalid." UserInfo={NSLocalizedDescription=Device is invalid.}
  • 10% of the time the error is the same as the one seen in iOS 11:
    Error Domain=CBErrorDomain Code=0 "Unknown error." UserInfo={NSLocalizedDescription=Unknown error.}
Practical Causes of centralManager:didFailToConnectPeripheral:error:
 
 
Q