iOS 8 核心蓝牙没有发现外围设备 [英] iOS 8 Core Bluetooth not discovering peripherals

查看:22
本文介绍了iOS 8 核心蓝牙没有发现外围设备的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm having trouble getting Core Bluetooth to discover peripherals on iOS 8. Same code works fine on iOS 7 device. Initially I thought it would be a permissions issue since I had been doing some iBeacon work and there are some changes in Core Location permissions on iOS 8. I couldn't find anything online that helped with that however. Here is a link to a sample project that works fine for me on iOS 7 but not on iOS 8:

https://github.com/elgreco84/PeripheralScanning

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

If I run this project on an iOS 7 device it will log advertisement data for a number of devices around me. On iOS 8 the only output I see is that the Central Manager state is "Powered On".

推荐答案

在您处于开机"状态之前,开始扫描外围设备是无效的.也许在你的 iOS7 设备上你很幸运,但代码仍然不正确.你的 centralManagerDidUpdateState: 应该是

It isn't valid to start scanning for peripherals until you are in the 'powered on' state. Perhaps on your iOS7 device you are lucky with timing, but the code is still incorrect. Your centralManagerDidUpdateState: should be

- (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

这篇关于iOS 8 核心蓝牙没有发现外围设备的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆