我无法获得核心蓝牙在iOS 8上发现外设.相同的代码在iOS 7设备上运行正常.最初,我以为这是一个权限问题,因为我一直在做一些iBeacon的工作,并且在iOS 8上的Core Location权限有一些变化.我找不到有用的东西.以下是一个示例项目的链接,在iOS 7上可用于我,但不在iOS 8上运行:
https://github.com/elgreco84/PeripheralScanning
如果我在iOS 7设备上运行此项目,它会记录我周围的一些设备的广告数据.在iOS 8中,我看到的唯一输出是中央管理器状态为“启动”.
解决方法
开始扫描外设,直到您处于“通电”状态是无效的.也许在您的iOS7设备上,您很幸运有时间,但代码仍然不正确.您的centralManagerDidUpdateState:应该是
- - (void)centralManagerDidUpdateState:(CBCentralManager *)central
- {
- switch (central.state)
- {
- case CBCentralManagerStateUnsupported:
- {
- NSLog(@"State: Unsupported");
- } break;
- case CBCentralManagerStateUnauthorized:
- {
- NSLog(@"State: Unauthorized");
- } break;
- case CBCentralManagerStatePoweredOff:
- {
- NSLog(@"State: Powered Off");
- } break;
- case CBCentralManagerStatePoweredOn:
- {
- NSLog(@"State: Powered On");
- [self.manager scanForPeripheralsWithServices:nil options:nil];
- } break;
- case CBCentralManagerStateUnknown:
- {
- NSLog(@"State: Unknown");
- } break;
- default:
- {
- }
- }
- }
并从didFinishLaunchingWithOptions中删除对scanForPeripheralsWithServices的调用