5

We need Get Data form BluetooothDevices to IOS devices.We are using core_bluetooth.frameworks. didDisconnectPeripheral call after didConnectPeripheral ever time.We got error is error is Error Domain=CBErrorDomain Code=7 "The specified device has disconnected from us." UserInfo={NSLocalizedDescription=The specified device has disconnected from us.}

We tried code is: //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 on/off

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

//Discover

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

We are not understand why it's ever time call didDisconnection after didConnectPeripheral. Please tell me what wrong in my code.

konda
  • 51
  • 1
  • 6
  • 2
    Have you tried the lightblue app from the App Store? It looks to me like a problem with your peripheral, not your code - it is the peripheral that is disconnecting for you – Paulw11 Oct 30 '15 at 09:14
  • @Paulw11 thanks for reply We tried LightBlue app.When i open Lightblue app .I got Device name when we click on device name it's showing message "Connection Alerts-->The Periperal disconnected while being interrogated." – konda Oct 30 '15 at 09:23
  • 1
    So I would definitely say that your peripheral has a problem. What is it? – Paulw11 Oct 30 '15 at 09:24
  • @Paulw11 thanks but in android they get data form peripheral(BluetoothDevice).Device is "PHARMCELL CAREOUSAEL" – konda Oct 30 '15 at 09:25
  • @Paulw11 please help me we need more proof peripheral has problem .Because we will plane Big deal to Clients. – konda Oct 30 '15 at 09:31
  • 3
    There's not much more I can do for you - I don't have that hardware but I can say that the LightBlue app is pretty solid, so if it has an issue there is something amiss. My code is more of an example but also works for basic connectivity. The only other thing I can think of is that the peripheral has some security type of configuration where you need to send specific data or the connection is dropped. Have you been provided with any documentation? – Paulw11 Oct 30 '15 at 09:46
  • I'd go with the same idea from Paulw11. Possibility: You may have to pair (or something similar, see the doc) to avoid a "quick disconnection". I've worked with some device like that. It was set to avoid "keeping the peripheral busy with unwanted outsider BLE apps". – Larme Oct 30 '15 at 11:00
  • 1
    I have the same error when I clear the pairing on the BLE device. My iOS still have the previous pairing info, tries to connect to the BLE device, which succeeds but right after I receive a didDisconnectPeripheral with the same error. – EricG May 26 '17 at 15:26
  • Hi, @EricG I know it's an old question and it's a long shot. but did you get to fix this issue, I'm having the same issue, after clearing the pairing, the pairing popup does not appear again. – TapulaRasa Jul 04 '23 at 12:39

0 Answers0