-(void)centralManagerDidUpdateState:(CBCentralManager *)central{
    switch (central.state) {
        case CBPeripheralManagerStatePoweredOn:
            NSLog(@"BLE已打开.");
            [self writeToLog:@"BLE已打开."];
            //扫描外围设备
            
            dispatch_async(dispatch_get_main_queue(), ^{
                [central scanForPeripheralsWithServices:nil options:@{CBCentralManagerScanOptionAllowDuplicatesKey:@YES}];
            });
            break;
            
        default:
            NSLog(@"此设备不支持BLE或未打开蓝牙功能,无法作为外围设备.");
            [self writeToLog:@"此设备不支持BLE或未打开蓝牙功能,无法作为外围设备."];
            break;
    }
}希望能得到错误的具体原因?

解决方案 »

  1.   

    还未编译程序,在default哪里报错:Cannot jump from switch statement to this case label。希望能得到错误的具体原因?
      

  2.   

    http://stackoverflow.com/questions/33550588/defining-a-block-in-a-switch-statement-results-in-a-compiler-error
      

  3.   

    呵呵,应该是作用域的问题,如果在case 的判断中是一些语句体,需要用 花括号 {} 括起来-(void)centralManagerDidUpdateState:(CBCentralManager *)central{
        switch (central.state) {
            case CBPeripheralManagerStatePoweredOn: {
                NSLog(@"BLE已打开.");
                [self writeToLog:@"BLE已打开."];
                //扫描外围设备
                 [central scanForPeripheralsWithServices:nil options:@{CBCentralManagerScanOptionAllowDuplicatesKey:@YES}];
                break;
             }
            default: {
                NSLog(@"此设备不支持BLE或未打开蓝牙功能,无法作为外围设备.");
                [self writeToLog:@"此设备不支持BLE或未打开蓝牙功能,无法作为外围设备."];
               }
                break;
        }
    }