5

BluetooothDevices から IOS デバイスへの Get Data が必要ですcore_bluetooth.frameworks。didConnectPeripheral の後に didDisconnectPeripheral を呼び出します。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];

//Bluetooth オン/オフ

-(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.";
    }
}

//発見する

 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];
        });
    }

//didConnectPeripheral

 [self.activePeripheral discoverServices:@[[CBUUID UUIDWithString:@"00001c00-d102-11e1-9b23-00025b00a5a5"]]];

//didDisconnectPeripheral

NSLog(@"error is %@",error.description);

didConnectPeripheral の後に didDisconnection を呼び出す理由がよくわかりません。私のコードで何が間違っているのか教えてください。

4

0 に答える 0