CoreBluetooth [警告] 未知错误:311 在 iOS 中使用 CoreBluetooth 框架重复连接和断开连接时发生

Posted

技术标签:

【中文标题】CoreBluetooth [警告] 未知错误:311 在 iOS 中使用 CoreBluetooth 框架重复连接和断开连接时发生【英文标题】:CoreBluetooth[WARNING] Unknown error: 311 Occurs when repeatedly connect and disconnect using CoreBluetooth Framework in iOS 【发布时间】:2013-03-12 15:30:03 【问题描述】:

当我尝试连接蓝牙设备时,它反复连接失败并显示错误CoreBluetooth[WARNING] Unknown error: 311。我正在使用 2 个 iPod 5 Touch 设备。

【问题讨论】:

【参考方案1】:

我也遇到过这个问题,这似乎是 Core Bluetooth 的 XPC 通信中的一个错误:

2013-03-22 14:49:24.652 Buggy[985:907] Connecting to peripheral <CBConcretePeripheral: 0x1dd4e150 UUID = (null), Name = "iPhone 5 #003014", IsConnected = NO>
2013-03-22 14:49:24.659 Buggy[985:907] CoreBluetooth[WARNING] Unknown error: 311
2013-03-22 14:49:24.661 Buggy[985:907] Failed to connect to peripheral <CBConcretePeripheral: 0x1dd4e150 UUID = (null), Name = "iPhone 5 #003014", IsConnected = NO>
2013-03-22 14:49:24.689 Buggy[985:907] Discovered peripheral <CBConcretePeripheral: 0x1dd644d0 UUID = (null), Name = "iPhone 5 #003014", IsConnected = NO> with advertisement data 
    kCBAdvDataLocalName = "iPhone 5 #003014";
    kCBAdvDataServiceUUIDs =     (
        "Unknown (<b2e74c08 96094371 a8f0978c 655700ea>)"
    );
, RSSI: -50
2013-03-22 14:49:24.692 Buggy[985:907] Connecting to peripheral <CBConcretePeripheral: 0x1dd644d0 UUID = (null), Name = "iPhone 5 #003014", IsConnected = NO>
2013-03-22 14:49:45.035 Buggy[985:110b] CoreBluetooth[ERROR] XPC connection interrupted, resetting
2013-03-22 14:49:45.050 Buggy[985:907] Central manager updated state to: 1
2013-03-22 14:49:45.116 Buggy[985:907] Central manager updated state to: 4
2013-03-22 14:49:47.271 Buggy[985:907] Central manager updated state to: 5

在这一点之后,事情又开始工作了,至少在几分钟后再次出现错误 311 循环之前。

这是一个对我来说可靠的解决方法:

// In centralManager:didFailToConnectPeripheral:error:, ARC enabled
if (error.code == 0) 
    self.centralManager.delegate = nil;
    self.centralManager = nil;
    // Remove all references to any peripherals you've been interacting with
    [self.peripherals removeAllObjects];

    /* Some delay (more than the next iteration of the runloop, less than 2 seconds) is required in order to:
     * • Allow ARC to drain the autorelease pool, ensuring destruction of the centralManager
     * • Allow Core Bluetooth to turn off the radio.
     *
     * This means that this workaround might not work if:
     * • Your code has another active central manager somewhere
     * • Another app is using BLE (in theory; I haven't tested this)
     */
    double delayInSeconds = 2.0;
    dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
    dispatch_after(popTime, dispatch_get_main_queue(), ^(void)
        self.centralManager = [[CBCentralManager alloc] initWithDelegate:self queue:dispatch_get_main_queue()];
        [self startScanning];
    );

【讨论】:

在成功连接到外围设备“CoreBluetooth[WARNING] Unknown error: 14”后出现此错误,导致其断开连接。有什么想法吗? 看起来您已经在 Stack Overflow 上发布了 this question。我不知道,但是you're not alone。【参考方案2】:

如果您在连接一段时间后遇到错误,那么此分析和解决方案可能会有所帮助:

http://lists.apple.com/archives/bluetooth-dev/2013/Jan/msg00069.html

【讨论】:

以上是关于CoreBluetooth [警告] 未知错误:311 在 iOS 中使用 CoreBluetooth 框架重复连接和断开连接时发生的主要内容,如果未能解决你的问题,请参考以下文章

ios- cbcentralManager 状态未知且 CoreBluetooth[WARNING] <CBConcreteCentralManager> 未通电

如何解决 [CoreBluetooth] 警告:对于具有多个设备连接的外围设备来说,这不是一个有效的特征

如何修复错误 [Vue 警告]:未知的自定义元素?

警告:文件上传错误 - 无法在第 0 行的未知中创建临时文件

DataTables 警告(表 id = 'table-filter'):从数据源请求未知参数 '0' 用于数据表中的第 0 行错误

数据表警告从第 0 行的数据源请求未知参数“1”