Reputation: 11755
In my implementation of the CBCentralManagerDelegate
protocol, I have the following function.
func centralManager(_ central: CBCentralManager,
didDisconnectPeripheral peripheral: CBPeripheral,
error: Error?) {
print(#function)
if error != nil {
print("Error in \(#function) :\n\(error!)")
return
}
......
// More useful code irrelevant to the question.
}
When the above function is called I can see the message below in the Xcode
debugging console.
centralManager(_:didDisconnectPeripheral:error:)
Error in centralManager(_:didDisconnectPeripheral:error:) :
Error Domain=CBErrorDomain Code=7 "The specified device has disconnected from us."
UserInfo={NSLocalizedDescription=The specified device has disconnected from us.}
Here is my question: I must be missing something (because too simple or too subtle), but why does is show an error because "The specified device has disconnected from us."
In the centralManager:didDisconnectPeripheral function, what else could I expect other than the device being disconnected?
I hope some enlighted expert can bring some light an explain why this is so.
Upvotes: 0
Views: 528
Reputation: 74
As per the Apple documentation:
If the disconnection was not initiated by cancelPeripheralConnection(_:), the cause is detailed in error.
I.e if You disconnect then you get no error but if They disconnect you see that through the error. Source: https://developer.apple.com/documentation/corebluetooth/cbcentralmanagerdelegate/1518791-centralmanager
Upvotes: 1