iOS BLE CentralManager didFailToConnect 到外围设备未被调用

标签 ios swift bluetooth-lowenergy core-bluetooth

如果外围设备已被中心发现,但就在用户按下按钮进行连接之前,外围设备超出范围,因此无法完成连接。 CoreBluetooth调用了什么方法? 我认为 centralManager didFailToConnect 会被调用,但在我的代码中它没有被调用,也许是因为连接根本没有启动? 在这种情况下,我应该使用哪种方法。 在此先感谢您的帮助。

public func centralManager(_ central: CBCentralManager, didFailToConnect peripheral: CBPeripheral, error: Error?) {

    print("[ERROR] Could not connect to peripheral \(peripheral.identifier.uuidString) error: \(error!.localizedDescription)")
}

最佳答案

如前一个答案所述,如果任何设备未启动连接过程,则不会调用任何委托(delegate)方法。didFailToConnect 方法仅在设备启动连接过程时调用,但由于任何设备无法连接的原因。

如果你想检查是否有任何设备可以连接,那么你需要为特定时间段创建一个计时器,如果在此期间没有扫描到任何设备,那么你可以显示一条消息,显示“没有可用的设备” "并再次检查设备。

关于iOS BLE CentralManager didFailToConnect 到外围设备未被调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48336748/

相关文章:

android - flutter blue 示例无法连接到 gatt 服务器

ios - 如何创建具有权利的新配置文件?

ios - 将 Unity3d 集成到 iOS UITabbarController/UINavigationController

ios - 无需标注即可转换 MKAnnotationView

ios - ARKit 中带有动画的 .fbx 文件

即使具有位置权限,也不会触发 Android BLE startDiscovery() 回调

ios - UIImageView 快速缩放和拖动

ios - 如何使用 MVVM 在 MonoTouch TableView 中绑定(bind)删除按钮

swift 错误 : cannot convert value of type B to type A in coercion

java - Bluetooth LE 通过应用程序在 Android 设备之间发送字符串数据