0

In my app I have a method that reconnects the device to the peripheral if it had previously gone out of range. I put an exception breakpoint in my app, and it seems to have crashed at this line:

[centralManager connectPeripheral:currentPeripheral.peripheral options:nil]; 

Here is the line of code in context of the method that manages reconnection:

-(void)reconnect:(int)patientID
{
for(EHOIPeripheral* currentPeripheral in pairedPeripherals)
{
    if(currentPeripheral.patientID == patientID)
    {
        DBHelper* dbHelper = [DBHelper getSharedInstance];
        Device* pairedDevice = [dbHelper getPairedDeviceForPatient:patientID];
        if(pairedDevice)
        {
            NSLog(@"Reconnecting patient %d with its peripheral %@.\nAddress: %@", patientID, currentPeripheral.peripheral.name, currentPeripheral.pairedDevice.address);
            [centralManager connectPeripheral:currentPeripheral.peripheral options:nil];
            // Read missed packets, if possible:
            if(currentPeripheral.calibrationComplete)
            {
                if(measurementCharacteristic)
                {
                    [currentPeripheral.peripheral readValueForCharacteristic:measurementCharacteristic];
                }
            }
            else
            {
                [currentPeripheral.peripheral discoverServices:[NSArray arrayWithObject:serviceUUID]];
            }
        }
    }
}
}

As soon as it hits this line I get an error from the console saying:

*** Assertion failure in -[CBCentralManager connectPeripheral:options:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/CoreBluetooth/CoreBluetooth-352.1/CoreBluetooth/CBCentralManager.m:257


*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid parameter not satisfying: peripheral != nil'

Is this is an issue with me not providing enough info in my info.plist? Or could this be an issue with peripheral not being nil and being passed into the method?

Faisal Syed
  • 921
  • 1
  • 11
  • 25
  • Is the peripheral you want to connect to there? What if the peripheral goes offline at any moment (battery dies, etc..)? You need to test that there peripheral is available before calling connectPeripheral, and you do that by making sure the peripheral is not nil. – H. Al-Amri Mar 02 '17 at 23:33
  • So you're saying I should add a check to make sure the peripheral != nil? – Faisal Syed Mar 02 '17 at 23:37
  • That would be the first thing I would check, make sure currentPeripheral.peripheral is not nil. If it isn't add a breakpoint and see if it changes to nil at any point. – H. Al-Amri Mar 04 '17 at 03:28

0 Answers0