Question

I keep getting this error when I run my app that uses CoreBluetooth on an iPhone 5: <CBConcreteCentralManager: 0x2007d590> is not powered on

But when I call state on my program's one and only CBCentralManager object, it returns 5, which is CBCentralManagerStatePoweredOn. So it's powered on, yet I get this error. The iPhone's Bluetooth is also enabled.

Just in general, when would this ever happen? I don't even know what is going on when the program runs because I'm getting what looks like conflicting messages.

Was it helpful?

Solution

You have to initially wait until the centralManager gets the callback from centralManagerDidUpdateState: when you're app boots up. Then every other time, I recommend checking the state prior to doing any centralManager calls. You're most likely calling scan or retrieve before the central has had a chance to update. Ensure you only call methods after you know it's on. You will not get the error if you wrap each call in if statements that check the state first.

- (void)centralManagerDidUpdateState:(CBCentralManager *)central
{
   if(central.state==CBCentralManagerStatePoweredOn)
   {
      //Now do your scanning and retrievals
   }
}

Otherwise just wrap your central inside a state check before each call:

if(yourCentral.state==CBCentralManagerStatePoweredOn)
{
//you're good to go on calling centralManager methods
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top