无法发现外围蓝牙低功耗设备

时间:2014-07-09 05:44:51

标签: ios iphone bluetooth-lowenergy ios8

我最近将手机升级到iOS Beta版本8并安装了我的iOS应用程序。很遗憾,我的应用无法再发现我的外设BLE设备了。我检查了任何文件,说明是否有任何变化,但没有找到。是否已在iOS 8中引入任何已知的API更改?我在iPhone 5s上测试 我的代码早先在IOS版本7.xx上运行

相关的代码:

[self.CM scanForPeripheralsWithServices:nil options:nil];

1 个答案:

答案 0 :(得分:1)

你在哪里开始扫描? 你应该打电话给

self.CM = [[CBCentralManager alloc] initWithDelegate:self queue:nil];

在viewDidLoad中或您需要的任何其他位置,然后仅在中央管理器状态打开时扫描外围设备:

-(void)centralManagerDidUpdateState:(CBCentralManager *)central{ switch (central.state) {
    case CBCentralManagerStatePoweredOff:
        NSLog(@"CoreBluetooth BLE hardware is powered off");
        break;
    case CBCentralManagerStatePoweredOn:
    {
        NSLog(@"CoreBluetooth BLE hardware is powered on and ready");
        [self.CM scanForPeripheralsWithServices:nil options:nil];
    }
        break;
    case CBCentralManagerStateResetting:
        NSLog(@"CoreBluetooth BLE hardware is resetting");
        break;
    case CBCentralManagerStateUnauthorized:
        NSLog(@"CoreBluetooth BLE state is unauthorized");
        break;
    case CBCentralManagerStateUnknown:
        NSLog(@"CoreBluetooth BLE state is unknown");
        break;
    case CBCentralManagerStateUnsupported:
        NSLog(@"CoreBluetooth BLE hardware is unsupported on this platform");
        break;
    default:
        break; }