Error Domain=CBErrorDomain Code=7 "指定的设备已与我们断开连接

kon*_*nda 5 core-bluetooth bluetooth-lowenergy cbcentralmanager cbperipheralmanager

我们需要从蓝牙设备获取数据到 IOS 设备core_bluetooth.frameworks。我们正在使用. didDisconnectPeripheral 每次都在 didConnectPeripheral 之后调用。我们得到的错误是错误是Error Domain=CBErrorDomain Code=7 "The specified device has disconnected from us." UserInfo={NSLocalizedDescription=The specified device has disconnected from us.}

我们试过的代码是://in ViewDidLoad

NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:NO], CBCentralManagerOptionShowPowerAlertKey, nil];
     self.central=[[CBCentralManager alloc] initWithDelegate:self queue:nil options:options];
     //self.central=[[CBCentralManager alloc] initWithDelegate:self queue:dispatch_get_global_queue(QOS_CLASS_BACKGROUND, 0)];
     self.discoveredPeripherals=[NSMutableArray new];
Run Code Online (Sandbox Code Playgroud)

//蓝牙开/关

-(void) centralManagerDidUpdateState:(CBCentralManager *)central {
NSString *stateString = nil;
    switch(central.state)
    {
        case CBCentralManagerStateResetting:
            stateString = @"The connection with the system service was momentarily lost, update imminent.";
            break;
        case CBCentralManagerStateUnsupported:
            stateString = @"The platform doesn't support Bluetooth Low Energy.";
            break;
        case CBCentralManagerStateUnauthorized:
            stateString = @"The app is not authorized to use Bluetooth Low Energy.";
            break;
        case CBCentralManagerStatePoweredOff:
            stateString = @"Bluetooth is currently powered off.";
            break;
        case CBCentralManagerStatePoweredOn:
            stateString = @"Bluetooth is currently powered on and available to use.";
    }
}
Run Code Online (Sandbox Code Playgroud)

//发现

 NSLog(@"Discovered peripheral %@ (%@)",peripheral.name,peripheral.identifier.UUIDString);
    if (![self.discoveredPeripherals containsObject:peripheral] ) {
        dispatch_async(dispatch_get_main_queue(), ^{
            [self.discoveredPeripherals addObject:peripheral];
            [self.tableview insertRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:self.discoveredPeripherals.count-1 inSection:0]] withRowAnimation:UITableViewRowAnimationLeft];
        });
    }
Run Code Online (Sandbox Code Playgroud)

//didConnectPeripheral

 [self.activePeripheral discoverServices:@[[CBUUID UUIDWithString:@"00001c00-d102-11e1-9b23-00025b00a5a5"]]];
Run Code Online (Sandbox Code Playgroud)

//didDisconnectPeripheral

NSLog(@"error is %@",error.description);
Run Code Online (Sandbox Code Playgroud)

我们不明白为什么总是在 didConnectPeripheral 之后调用 didDisconnection。请告诉我我的代码有什么问题。