iOS8和BTLE | CBCentralManager无法find外围设备

我有一个iOS应用程序使用BTLE连接到一个设备(arduino)。 在我的iPad iOS 7上,一切正常。升级到iOS 8后,CBCentralManager没有find任何外设。

- (void)startScanningForSupportedUUIDs { [self.centralManager scanForPeripheralsWithServices:nil options:nil]; } 

我不知道可能是什么问题。

我有解决scheme,出于某种原因,在iOS 8实例化您的CBManager后有一些延迟。 您需要开始扫描CBCentralManager打开时,在此方法中:

 -(void)centralManagerDidUpdateState:(CBCentralManager *)central{ switch (central.state) { case CBCentralManagerStatePoweredOff: NSLog(@"CoreBluetooth BLE hardware is powered off"); break; case CBCentralManagerStatePoweredOn: { NSLog(@"CoreBluetooth BLE hardware is powered on and ready"); NSArray *uuidArray = [NSArray arrayWithObjects:[CBUUID UUIDWithString:TRANSFER_SERVICE_UUID], nil]; NSDictionary *options = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:YES] forKey:CBCentralManagerScanOptionAllowDuplicatesKey]; [centralManager scanForPeripheralsWithServices:uuidArray options:options]; } break; case CBCentralManagerStateResetting: NSLog(@"CoreBluetooth BLE hardware is resetting"); break; case CBCentralManagerStateUnauthorized: NSLog(@"CoreBluetooth BLE state is unauthorized"); break; case CBCentralManagerStateUnknown: NSLog(@"CoreBluetooth BLE state is unknown"); break; case CBCentralManagerStateUnsupported: NSLog(@"CoreBluetooth BLE hardware is unsupported on this platform"); break; default: break; } 

在IOS 7中,即使在CBCentralManager准备就绪之前,您也可以通过开始BLE扫描。 IOS 7曾经在这种情况下吐出警告 –

CoreBluetooth [API MISUSEUSE]只能在开机状态下接受命令

使用IOS8 – 警告不再出现,扫描实际上并没有开始。 为了解决这个问题,等待CBCentral启动 – 即等待CBCentral manager进入“CBCentralManagerStatePoweredOn”状态,然后开始扫描。 它可以正常工作:)