sim
sim

Reputation: 249

Unable to discover peripheral Bluetooth Low Energy devices

I recently upgraded my phone to the iOS Beta version 8 and installed my iOS app . Unfortunately my app no longer is able to discover my peripheral BLE device. I checked for any documentation which says if there has been any change but found none. Has there been any known API changes that have been introduced as part of iOS 8 ? I am testing on iPhone 5s My code was working earlier on IOS version 7.xx

Relevant piece of code :

[self.CM scanForPeripheralsWithServices:nil options:nil];

Upvotes: 0

Views: 435

Answers (1)

The Good Giant
The Good Giant

Reputation: 1780

Where are you launching the scan? You should call

self.CM = [[CBCentralManager alloc] initWithDelegate:self queue:nil];

in the viewDidLoad or anywhere else you need to to that, and then scan for peripherals only when the centralmanager state is on:

-(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");
        [self.CM scanForPeripheralsWithServices:nil options:nil];
    }
        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; }

Upvotes: 1

Related Questions