iOS 8核心蓝牙无法发现外设

前端之家收集整理的这篇文章主要介绍了iOS 8核心蓝牙无法发现外设前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我无法获得核心蓝牙在iOS 8上发现外设.相同的代码在iOS 7设备上运行正常.最初,我以为这是一个权限问题,因为我一直在做一些iBeacon的工作,并且在iOS 8上的Core Location权限有一些变化.我找不到有用的东西.以下是一个示例项目的链接,在iOS 7上可用于我,但不在iOS 8上运行:

https://github.com/elgreco84/PeripheralScanning

如果我在iOS 7设备上运行此项目,它会记录我周围的一些设备的广告数据.在iOS 8中,我看到的唯一输出是中央管理器状态为“启动”.

解决方法

开始扫描外设,直到您处于“通电”状态是无效的.也许在您的iOS7设备上,您很幸运有时间,但代码仍然不正确.您的centralManagerDidUpdateState:应该是
  1. - (void)centralManagerDidUpdateState:(CBCentralManager *)central
  2. {
  3. switch (central.state)
  4. {
  5. case CBCentralManagerStateUnsupported:
  6. {
  7. NSLog(@"State: Unsupported");
  8. } break;
  9.  
  10. case CBCentralManagerStateUnauthorized:
  11. {
  12. NSLog(@"State: Unauthorized");
  13. } break;
  14.  
  15. case CBCentralManagerStatePoweredOff:
  16. {
  17. NSLog(@"State: Powered Off");
  18. } break;
  19.  
  20. case CBCentralManagerStatePoweredOn:
  21. {
  22. NSLog(@"State: Powered On");
  23. [self.manager scanForPeripheralsWithServices:nil options:nil];
  24. } break;
  25.  
  26. case CBCentralManagerStateUnknown:
  27. {
  28. NSLog(@"State: Unknown");
  29. } break;
  30.  
  31. default:
  32. {
  33. }
  34.  
  35. }
  36. }

并从didFinishLaunchingWithOptions中删除对scanForPeripheralsWithServices的调用

猜你在找的iOS相关文章