关于CoreBluetooth断开重连失败问题

案例:

关于断开重连,苹果官方文档是这样说的:

When the user leaves home, the iOS device may eventually become out of range of the lock,causing the connection to the lock to be lost. At this point, the app can simply call the connectPeripheral:options:method of the CBCentralManager class, and because connection requests do not time out, the iOS device will reconnect when the user returns home.

只需要断开后调用connectPeripheral: options:方法就行了。

现在可能出现重连不上的情况。

分析:

可能使用情况是:

- (void)centralManager:(CBCentralManager *)central didDisconnectPeripheral:(CBPeripheral *)peripheral error:(NSError *)error

{

    ......

    [myCBCManager connectPeripheral:peripheral options:nil];

}

这时可能重连不上。原因是:代理传过来的peripheralnil的。

解决:

搜索和连接的peripheral,记得在系统内存中保留引用,也就是说不要释放。

这样代理才能正确传回peripheral,重连成功。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容