首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >CoreBluetooth[WARNING]未知错误:在iOS中使用CoreBluetooth框架重复连接和断开连接时发生311

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

Stack Overflow用户
提问于 2013-03-12 23:30:04
回答 2查看 1.8K关注 0票数 2

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

EN

回答 2

Stack Overflow用户

发布于 2013-03-23 06:58:38

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

代码语言:javascript
复制
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循环在几分钟后再次发生。

这是一个对我来说很可靠的变通方法:

代码语言:javascript
复制
// 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];
    });
}
票数 7
EN

Stack Overflow用户

发布于 2013-12-13 04:12:54

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

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

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15365348

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档