iOS的8核心蓝牙未发现外设 [英] iOS 8 Core Bluetooth not discovering peripherals

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

问题描述

我遇到了麻烦核心蓝牙发现在iOS上外设8相同code正常工作的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:

<一个href=\"https://github.com/elgreco84/PeripheralScanning\">https://github.com/elgreco84/PeripheralScanning

如果我在iOS 7设备将记录广告数据对于一些在我身边的设备上运行这个项目。在iOS 8我看到的唯一输出是中央管理器状态为上电。

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设备上你是幸运的具有定时,但code是仍然不正确。你的 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天全站免登陆