iOS 10.0以后蓝牙'CBCentralManagerStateUnknown' is deprecated: first deprecated in iOS 10.0 - Use CBManagerState instead这类警告

-(void)centralManagerDidUpdateState:(CBCentralManager *)central
{
//    NSLog(@"状态改变了 %ld",(long)central.state);
//    NSLog(@"状态改变了666:%@",central);
    [self startScan];
    switch (central.state) {
        case CBCentralManagerStateUnknown:CBCentralManagerStateUnknown' is deprecated: first deprecated in iOS 10.0 - Use CBManagerState instead
            NSLog(@"CBCentralManagerStateUnknown---》未知");
            break;
        case CBManagerStateResetting:
            NSLog(@"CBCentralManagerStateResetting---》正在重置");
            break;
        case CBManagerStateUnsupported:
            NSLog(@"CBCentralManagerStateUnsupported---》不支持");
            break;
        case CBManagerStateUnauthorized:
            NSLog(@"CBCentralManagerStateUnauthorized---》设备未授权");
            break;
        case CBManagerStatePoweredOff:
            NSLog(@"CBCentralManagerStatePoweredOff---》关闭");
            //发送消息
            [[NSNotificationCenter defaultCenter]postNotificationName:@"CBManagerStatePoweredOff" object:nil userInfo:@{@"CBManagerStatePoweredOff":@"off"}];
            break;
        case CBManagerStatePoweredOn:
            NSLog(@"CBManagerStatePoweredOn---》打开");
            // 这里已确认蓝牙已打开才开始扫描周围的外设。第一个参数nil就是扫描周围所有的外设。
            [central scanForPeripheralsWithServices:nil options:nil];
            break;
        default:
            break;
    }
}

出现这个警告,是说iOS10.0以后蓝牙的这几个方法名字换了一下而已,简单讲就是

CBCentralManagerStateUnknown变成CBManagerStateUnknown,就是把中间Central去调而已,外国人觉得看起来精简了。

posted on 2017-12-08 09:55  高彰  阅读(4339)  评论(0编辑  收藏  举报

导航