1:用蓝牙工具测试是否是硬件问题,我用lightBlue测试硬件是没问题的
2:那就是我的问题了,最后解决如下:需再外部断开的回调中,重新初始化蓝牙设备管理对象,重新启动搜索就可以搜索到该设备了
//Peripherals断开连接
- (void)centralManager:(CBCentralManager *)central didDisconnectPeripheral:(CBPeripheral *)peripheral error:(NSError *)error{
NSLog(@">>>外设连接断开连接 %@: %@___需要连接的设备:%@__来自外部断开:%d", [peripheral name], [error localizedDescription],[self.needReConnectPeripheral name],isFromReconnect);
//清除当前连接
[self removeDisconnectPeripheral:peripheral];
if(isFromReconnect){//来自重连前的断开
isFromReconnect = NO;
if(self.needReConnectPeripheral){
self.peripheral = self.needReConnectPeripheral;
[manager connectPeripheral:self.peripheral options:nil];
}
}else{//来自外部断开
//清除所有重新开始
[self.peripheralArray removeAllObjects];
//初始化并设置委托和线程队列,最好一个线程的参数可以为nil,默认会就main线程
manager = [[CBCentralManager alloc] initWithDelegate:self queue:dispatch_get_main_queue()];
[manager scanForPeripheralsWithServices:nil options:0];
}
}
网友评论