Invalid Parameter Not Satisfying: peripheral != nil

时间:2017-03-02 23:28:58

标签: ios objective-c bluetooth cbcentralmanager

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?

0 个答案:

没有答案