问题描述:

Currently trying to get a Bluteooth sample working.

I'm using this sample as reference - http://developer.apple.com/library/mac/#samplecode/HeartRateMonitor/Listings/HeartRateMonitor_HeartRateMonitorAppDelegate_m.html#//apple_ref/doc/uid/DTS40011322-HeartRateMonitor_HeartRateMonitorAppDelegate_m-DontLinkElementID_4

Bluetooth is enabled on my device.

I've tried using code like:

_manager = new CBCentralManager ();

_manager.DiscoveredPeripheral += HandleDiscoveredPeripheral;

_manager.ConnectedPeripheral += HandleConnectedPeripheral;

_manager.DisconnectedPeripheral += HandleDisconnectedPeripheral;

and I've tried writing my own delegate inheriting from CBCentralManagerDelegate

but when I call StartScan

 void StartScan ()

{

var spp = Guid.Parse("00001101-0000-1000-8000-00805f9b34fb");

_manager.ScanForPeripherals(new [] { spp }, null);

}

then I see an error:

bluetooth1[1210:907] CoreBluetooth[WARNING] <CBConcreteCentralManager: 0x9beea0> is not powered on

Looking around for this error I've found just a couple of hits:

  • What causes CBCentralManagerStateUnknown in iOS?
  • http://www.zitao.org/wiki/development-log/le-zeng/2012-Nov-week1-devnote.html

But neither of these is particularly helpful...

I tried delaying start until the state changed:

 void HandleUpdatedState (object sender, EventArgs e)

{

// more to do here....

Console.WriteLine("State updated " + e.ToString());

switch (_manager.State) {

case CBCentralManagerState.PoweredOn:

_manager.DiscoveredPeripheral += HandleDiscoveredPeripheral;

_manager.ConnectedPeripheral += HandleConnectedPeripheral;

_manager.DisconnectedPeripheral += HandleDisconnectedPeripheral;

StartScan();

break;

case CBCentralManagerState.Unauthorized:

break;

}

}

  • but this never seems to be called.

I've also tried to run the xcode sample, but the force is not with me today...

Anyone got any ideas what CBConcreteCentralManager: 0x9beea0 is not powered on means and how to solve it here?

网友答案:

Answer: To get past this in MonoTouch I had to use a different constructor:

CBCentralManager(_delegate, MonoTouch.CoreFoundation.DispatchQueue.CurrentQueue) 

When I switched to that it started working...

相关阅读:
Top