iOS 关于蓝牙开发成功连接后,将外部蓝牙设备断电断开连接后再次插上电后app搜索不到该蓝牙设备问题

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];
    }

}
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容