iOS8 and BTLE | CBCentralManager unable to find peripherals
Asked Answered
A

2

9

I have an iOS app that is connecting to a device (arduino) using a BTLE. Everything is working fine on my iPad iOS 7. After upgrading to iOS 8, the CBCentralManager is not finding any peripherals.

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

}

I don't know what can be the problem.

Almund answered 19/8, 2014 at 17:19 Comment(0)
S
16

I have the solution, for some reason in iOS 8 there is some delay after instantiate your CBManager. You need to start to scan when the CBCentralManager is on, 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;
}
Sultan answered 8/9, 2014 at 20:45 Comment(0)
C
1

In IOS 7 you could get away by starting a BLE scan even before the CBCentralManager was ready. IOS 7 used to spit out a warning in such cases -

CoreBluetooth[API MISUSE] can only accept commands while in the powered on state

With IOS8 - the warning no more appears and the scan does not actually start. To overcome the problem, wait for the CBCentral to power on - ie, wait for CBCentral manager to get to the "CBCentralManagerStatePoweredOn" state and then start the scan. It works fine with that change:)

Caddie answered 16/10, 2014 at 23:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.