CoreBluetooth蓝牙扫描协议问题

来源:互联网 发布:蚁群算法流程 编辑:程序博客网 时间:2024/06/03 11:32

ios蓝牙协议比较简单,实现一些常用的功能只需要调用相对的方法就会触发相应的协议,不过在ios8中调用扫描方法却无法触发相对应的协议,不知道为什么?


解决方法如下:

//开始扫瞄
-(void)scanForPer{
    
    if (!TARGET_IPHONE_SIMULATOR) {
        NSDictionary *options = [NSDictionary
                                 dictionaryWithObject:[NSNumber numberWithBool:NO]
                                 forKey:CBCentralManagerScanOptionAllowDuplicatesKey];
        //ServicesUUIDs
        [self.centralManager scanForPeripheralsWithServices:ServicesUUIDs options:options];
    }
}


需要在此协议中再次调用一次才会执行

#pragma mark - ====== centralManager methods and delegate ======
- (void)centralManagerDidUpdateState:(CBCentralManager *)central{
    
    switch (central.state) {//蓝牙状态的改变
        case CBCentralManagerStatePoweredOn:{
            [self scanForPer];
        }
            break;
        default:
            break;
    }
}

0 0