0

We are developing a new App for the iPad (iOS). The new App needs to access the Buletooth device. We expect to use CoreBluetooth framework to realize it. However, the state of the CBCentralManager instance is always Unsupported. Why? How to solve it?

We develop the App on the MaxBook Pro OS X EI Captan V10.11.4. The version of Xcode is V7.3.1.

The followings are the codes.

class BluetoothService: NSObject, CBCentralManagerDelegate
{
     var centralMgr: CBCentralManager?

     func initializeCenral(){
               centralMgr = CBCentralManager(delegate: self, queue: nil)
    }

   @objc func centralManagerDidUpdateState(central: CBCentralManager){
         switch central.state{
         case CBCentralManagerState.PowerOff:
               print("Power Off")
         case CBCentralManagerState.PowerOn:
               print("Power On")
         case CBCentralManagerState.Resetting:
               print("Resetting")
         case CBCentralManagerState.Unsupported:
               print("Unsupported") // always at this state
        default: break
       }
   }

   //...

}//#

<== I created a new project for Command Line tool, and let it run the same codes on the local MacBook. In this case, the state of CBCentralManager becomes to PowerOn. It means that the CoreBluetooth Cannot run on any simulators.

  • 1
    What device are you testing on? Bluetooth is not supported on the simulator. – Paulw11 May 18 '16 at 10:43
  • I'll add to Paulw11 comments: What device exactly? For instance, iPad 2 supports iOS9 (and so Swift), but is not BLE compatible (doesn't have the chip). – Larme May 18 '16 at 10:48
  • The target of the App is the latest iPad, iPad 2, iPad Air, or iPad Air 2. Thank you very much, Paulw11. It is the problem of the simulator. I created a new project for Command Line tool, and let it run the same codes on the local MacBook. In this case, the state of CBCentralManager becomes to PowerOn. If the codes of CoreBluetooth cannot run on the simulator, how can I debug the codes? – Kevin Wang May 19 '16 at 00:47
  • Thank you very much, Larme! – Kevin Wang May 19 '16 at 01:04
  • 1
    You have to debug using an actual device connected to your Mac by USB – Paulw11 May 19 '16 at 02:13
  • Really appreciate your information! I will try to debug the program debug using an actual iPad connected to the Mac by USB. – Kevin Wang May 20 '16 at 07:59
  • This question has been indeed answered. How can I mark it as "answered"? – Kevin Wang May 20 '16 at 08:07

0 Answers0