cordova-plugin-ble-central icon indicating copy to clipboard operation
cordova-plugin-ble-central copied to clipboard

retrievePeripheralWithUUID crashing if uuid not valid

Open markarupert opened this issue 2 years ago • 1 comments

If you attempt to connect to an invalid BLE address the app crashes on iOS. Added the 2 lines below for a nil check to resolve it .

This is for version 143.

- (CBPeripheral*)retrievePeripheralWithUUID:(NSString*)uuid {
    NSUUID *typedUUID = [[NSUUID alloc] initWithUUIDString:uuid];

// FIX CRASH FOR INVALID UUID
    if (typedUUID == nil)
        return(nil);


    NSArray *existingPeripherals = [manager retrievePeripheralsWithIdentifiers:@[typedUUID]];
    CBPeripheral *peripheral = nil;
    if ([existingPeripherals count] > 0) {
        peripheral = [existingPeripherals firstObject];
        [peripherals addObject:peripheral];
    }
    return peripheral;
}

markarupert avatar Mar 07 '22 15:03 markarupert

Good pickup! I'll put it on my list... patches welcome however if you have the time & expertise to assist.

peitschie avatar Mar 08 '22 09:03 peitschie