案例:
關(guān)于斷開重連抄囚,蘋果官方文檔是這樣說的:
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.
只需要斷開后調(diào)用connectPeripheral: options:
方法就行了忠怖。
現(xiàn)在可能出現(xiàn)重連不上的情況喷好。
分析:
可能使用情況是:
- (void)centralManager:(CBCentralManager *)central didDisconnectPeripheral:(CBPeripheral *)peripheral error:(NSError *)error
{
......
[myCBCManager connectPeripheral:peripheral options:nil];
}
這時(shí)可能重連不上。原因是:代理傳過來的peripheral
是nil
的沾谓。
解決:
搜索和連接的peripheral
熙揍,記得在系統(tǒng)內(nèi)存中保留引用,也就是說不要釋放曼尊。
這樣代理才能正確傳回peripheral
,重連成功算谈。