IOS8 and BTLE | CBCentralManager cannot find peripherals

I have an iOS application that connects to a device (arduino) using BTLE. Everything works fine on my iPad iOS 7. After upgrading to iOS 8, CBCentralManager does not find any peripherals.

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

I do not know what the problem is.

+8
ios ios8 core-bluetooth btle
source share
2 answers

I have a solution, for some reason in iOS 8 there is some delay after creating an instance of your CBManager. You need to start scanning when CBCentralManager is enabled, in this method:

 -(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; } 
+15
source share

In iOS 7, you can get away by starting a BLE scan before the CBCentralManager is ready. In such cases, iOS 7 issued a warning -

CoreBluetooth [API MISUSE] can only accept commands when it is on

With IOS8 - the warning no longer appears, and the scan does not actually start. To overcome this problem, wait for CBCentral to turn on - i.e. wait for the CBCentral manager to transition to the "CBCentralManagerStatePoweredOn" state and then run the scan. It works great with this change :)

0
source share

All Articles