Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS8 and BTLE | CBCentralManager unable to find peripherals

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.

like image 928
user1561249 Avatar asked Aug 19 '14 17:08

user1561249


1 Answers

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;
}
like image 73
Pablo Martinez Avatar answered Oct 22 '22 15:10

Pablo Martinez