gpt4 book ai didi

ios - CBCentralManager 未开机

转载 作者:行者123 更新时间:2023-11-29 02:09:26 24 4
gpt4 key购买 nike

_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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com