关于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,重连成功。

你可能感兴趣的:(关于CoreBluetooth断开重连失败问题)