iOS 8核心蓝牙没有发现外围设备

Ric*_*rts 14 iphone bluetooth ios core-bluetooth

我无法让Core Bluetooth在iOS 8上发现外设.相同的代码在iOS 7设备上运行良好.最初我认为这将是一个权限问题,因为我一直在做一些iBeacon工作,并且在iOS 8上的核心位置权限有一些变化.但我在网上找不到任何帮助.这是一个示例项目的链接,适用于iOS 7但不适用于iOS 8:

https://github.com/elgreco84/PeripheralScanning

如果我在iOS 7设备上运行此项目,它将记录我周围的许多设备的广告数据.在iOS 8上,我看到的唯一输出是Central Manager状态为"Powered On".

Pau*_*w11 32

在处于"开机"状态之前,开始扫描外围设备是无效的.也许在你的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:
        {
        }

    }
}
Run Code Online (Sandbox Code Playgroud)

并删除scanForPeripheralsWithServices来自的电话didFinishLaunchingWithOptions

  • 非常感谢.你救了我把我的HRM扔出窗外. (2认同)