16

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.

Tommy Devoy
  • 13,441
  • 3
  • 48
  • 75
sudo
  • 5,604
  • 5
  • 40
  • 78

1 Answers1

24

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
}
Gordon Gustafson
  • 40,133
  • 25
  • 115
  • 157
Tommy Devoy
  • 13,441
  • 3
  • 48
  • 75
  • Yep, that was the problem. Thanks. – sudo Jul 08 '13 at 05:48
  • This solved the issue for me thank you. For some reason this started happening to me when I upgraded to Xcode 5 GM simulator. – Dan Sep 15 '13 at 12:53
  • 1
    I'm pretty sure Apple is no longer supporting BLE simulator support in Xcode 5 – Tommy Devoy Sep 16 '13 at 05:52
  • I think it was never updating the state because it saw no BLE devices nearby. When I asked the question, I didn't know that basically nothing but iPhones and heart monitors use BLE, and I was trying to make it see my car's Bluetooth stereo. – sudo Apr 05 '14 at 01:04
  • Also, I was not using the simulator. – sudo May 13 '14 at 05:11
  • This helped me to solve warning, Do I need to check other state like CBCentralManagerStateResetting before performing BLE operation? – Vishwa Patel Aug 12 '14 at 08:39