我在让 Core Bluetooth 发现 iOS 8 上的外围设备时遇到问题。相同的代码在 iOS 7 设备上运行良好。最初,我认为这可能是一个权限问题,因为我一直在做一些 iBeacon 工作,并且 iOS 8 上的核心位置权限发生了一些变化。但是,我在网上找不到任何对此有帮助的内容。下面是一个示例项目的链接,该项目在 iOS 7 上运行良好,但在 iOS 8 上运行不佳:
https://github.com/elgreco84/PeripheralScanning https://github.com/elgreco84/PeripheralScanning
如果我在 iOS 7 设备上运行这个项目,它将记录我周围许多设备的广告数据。在 iOS 8 上,我看到的唯一输出是 Central Manager 状态为“Powered On”。
在处于“开机”状态之前,开始扫描外围设备是无效的。也许在您的 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:
{
}
}
}
并删除对scanForPeripheralsWithServices
from didFinishLaunchingWithOptions
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)