ios - CBCentralManager 未开机

标签 ios macos bluetooth bluetooth-lowenergy discovery

_manager = [[CBCentralManager alloc] initWithDelegate:self queue:nil];
[NSThread sleepForTimeInterval:10]; // waiting for centralManagerDidUpdateState invocation
[_manager scanForPeripheralsWithServices:@[ _serviceUUID ] options:nil]; // warning here

...

- (void)centralManagerDidUpdateState:(CBCentralManager *)central {
    NSLog(@"CBCentralManager state is %i", (int)central.state);
}

- (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI {
    NSLog(@"Found peripheral: %@", peripheral);
    ...
}

出于某种原因,委托(delegate) centralManagerDidUpdateState 从未被调用,我收到警告:

2015-04-04 12:59:20.850 xctest[30276:303] CoreBluetooth[WARNING] is not powered on

同时开始发现外围设备。据我所知,它应该可以在 OSX 上运行(我正在攻读 MBA 2013 和 OSX Maverics 并正在运行 XCTest)。蓝牙已打开,我可以运行 LightBlue 应用程序并发现一些 BLE 设备(我确定在测试我的代码时没有 BLE 应用程序正在运行)。所以没有 didDiscoverPeripheral 像预期的那样被调用。

最佳答案

对于 OS X 10.13.2,CBCentralManager.init() 的队列参数必须为非零才能触发回调,例如在 swift

manager = CBCentralManager(
  delegate: self,
  queue: DispatchQueue(label: "BT_queue"))

关于ios - CBCentralManager 未开机,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29444090/

相关文章:

ios - UITableViewCell 字体大小不变

ios - Xcode 4.4 将我的 iOS 项目变成了 Mac OS X 项目!我怎样才能解决这个问题?

swift - 如何快速蓝牙连接设备?

mobile - 将 Adob​​e AIR 移动应用程序无线连接到 Arduino - 有哪些选项?

ios - 我可以在没有iOS应用的情况下将小部件提交给Apple Store吗?

android - 每个线段的不同颜色?

ios - 无法将类型 '(User) -> Dictionary<String, String>' 的值转换为预期的参数类型 'Dictionary<String, String>'

c++ - 在 Yosemite 中通过 g++ 链接 SOIL 的问题

macos - 在 OS X 上以编程方式查找共享库中本地符号的偏移量

android - 关于在 Android 应用程序中实现 OBEX 的任何示例?