ios - CoreBluetooth / CBCentralManagerDelegate 中的一条奇怪消息
问题描述
在我的CBCentralManagerDelegate
协议实现中,我具有以下功能。
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.
}
调用上述函数时,我可以在Xcode
调试控制台中看到以下消息。
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.}
这是我的问题:我一定遗漏了一些东西(因为太简单或太微妙),但为什么会显示错误,因为“指定的设备已与我们断开连接。 ”
在centralManager:didDisconnectPeripheral函数中,除了设备断开连接之外,我还能期待什么?
我希望一些开明的专家能带来一些启发,解释为什么会这样。
解决方案
根据苹果文档:
If the disconnection was not initiated by cancelPeripheralConnection(_:), the cause is detailed in error.
即,如果您断开连接,那么您不会收到任何错误,但如果他们断开连接,您会通过错误看到这一点。来源:https ://developer.apple.com/documentation/corebluetooth/cbcentralmanagerdelegate/1518791-centralmanager
推荐阅读
- arrays - 如何在函数内发送整个数组并将其转移并带回主代码?
- node.js - 设置 PORT NodeJs Heroku
- laravel-8 - 我们应该在哪里调度使用 Illuminate\Auth\Events\Registered;
- javascript - 提交带有克隆字段的表单
- ruby - 如何让 linux 系统使用 RVM for Ruby?
- python - Torch.nn 有特定的激活函数吗?
- javascript - 如何先按属性值排序,然后按日期排序
- reactjs - 在 redux createAsyncThunk 中返回数据数组时,Typescript 抛出错误
- azure - 应用服务环境中的 Azure 函数应用和 Azure SignalR
- azure - 如何在 Azure 数据工厂触发时检查是否正在上传某些文件(允许在 ADF 中上传时读取文件)