_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);
...
}
出于某种原因,代表centralManagerDidUpdateState则永远不会调用和我得到警告:CBCentralManager没有通电
2015-04-09 12:59:20.850 xctest [30276:303] CoreBluetooth [警告] 未通电
开始发现外设时。 AFAIK它应该在OSX上工作(我在2013年MBA和OSX Maverics上运行XCTest)。蓝牙已打开,我可以运行LightBlue应用程序并发现一些BLE设备(我确定在测试代码时没有运行BLE应用程序)。所以没有didDiscoverPeripheral
按预期调用。
可能重复的[无法蓝牙设备连接在IOS 8甚至现有的代码没有找到蓝牙和它回环非常细的上IOS 7最主要](http://stackoverflow.com/questions/26074216/无法连接蓝牙设备在IOS 8甚至现有的代码找不到bluet) – Paulw11 2015-04-04 08:31:00
测试核心蓝牙是棘手的。你应该仔细计划。但是我会说你手动测试CB部件要好得多,因为太多的错误因素使自动化测试变得不可靠。您应该将小型模块/库/接口中的CB交互分开,并且只测试与该接口的交互,您可以轻松地将任何返回值和回调替换为任何调用。 – allprog 2015-04-05 13:30:30