diff --git a/src/platform/Darwin/BlePlatformDelegateImpl.mm b/src/platform/Darwin/BlePlatformDelegateImpl.mm index 675381dc07d525..8f74bb8244feff 100644 --- a/src/platform/Darwin/BlePlatformDelegateImpl.mm +++ b/src/platform/Darwin/BlePlatformDelegateImpl.mm @@ -45,17 +45,14 @@ BLE_CONNECTION_OBJECT connObj, const ChipBleUUID * svcId, const ChipBleUUID * charId) { bool found = false; - CBUUID * serviceId = nil; - CBUUID * characteristicId = nil; - CBPeripheral * peripheral = (__bridge CBPeripheral *) connObj; - if (NULL != svcId) { - serviceId = [UUIDHelper GetShortestServiceUUID:svcId]; + if (NULL == svcId || NULL == charId) { + return found; } - if (NULL != charId) { - characteristicId = [CBUUID UUIDWithData:[NSData dataWithBytes:charId->bytes length:sizeof(charId->bytes)]]; - } + CBUUID * serviceId = [UUIDHelper GetShortestServiceUUID:svcId]; + CBUUID * characteristicId = [CBUUID UUIDWithData:[NSData dataWithBytes:charId->bytes length:sizeof(charId->bytes)]]; + CBPeripheral * peripheral = (__bridge CBPeripheral *) connObj; for (CBService * service in peripheral.services) { if ([service.UUID.data isEqualToData:serviceId.data]) { @@ -76,17 +73,15 @@ BLE_CONNECTION_OBJECT connObj, const ChipBleUUID * svcId, const ChipBleUUID * charId) { bool found = false; - CBUUID * serviceId = nil; - CBUUID * characteristicId = nil; - CBPeripheral * peripheral = (__bridge CBPeripheral *) connObj; - - if (NULL != svcId) { - serviceId = [UUIDHelper GetShortestServiceUUID:svcId]; - } - if (NULL != charId) { - characteristicId = [CBUUID UUIDWithData:[NSData dataWithBytes:charId->bytes length:sizeof(charId->bytes)]]; + if (NULL == svcId || NULL == charId) { + return found; } + CBUUID * serviceId = [UUIDHelper GetShortestServiceUUID:svcId]; + CBUUID * characteristicId = characteristicId = [CBUUID UUIDWithData:[NSData dataWithBytes:charId->bytes + length:sizeof(charId->bytes)]]; + CBPeripheral * peripheral = (__bridge CBPeripheral *) connObj; + for (CBService * service in peripheral.services) { if ([service.UUID.data isEqualToData:serviceId.data]) { for (CBCharacteristic * characteristic in service.characteristics) { @@ -135,21 +130,15 @@ BLE_CONNECTION_OBJECT connObj, const ChipBleUUID * svcId, const ChipBleUUID * charId, PacketBufferHandle pBuf) { bool found = false; - CBUUID * serviceId = nil; - CBUUID * characteristicId = nil; - NSData * data = nil; - CBPeripheral * peripheral = (__bridge CBPeripheral *) connObj; - - if (NULL != svcId) { - serviceId = [UUIDHelper GetShortestServiceUUID:svcId]; - } - if (NULL != charId) { - characteristicId = [CBUUID UUIDWithData:[NSData dataWithBytes:charId->bytes length:sizeof(charId->bytes)]]; - } - if (!pBuf.IsNull()) { - data = [NSData dataWithBytes:pBuf->Start() length:pBuf->DataLength()]; + if (NULL == svcId || NULL == charId || pBuf.IsNull()) { + return found; } + CBUUID * serviceId = [UUIDHelper GetShortestServiceUUID:svcId]; + CBUUID * characteristicId = [CBUUID UUIDWithData:[NSData dataWithBytes:charId->bytes length:sizeof(charId->bytes)]]; + NSData * data = [NSData dataWithBytes:pBuf->Start() length:pBuf->DataLength()]; + CBPeripheral * peripheral = (__bridge CBPeripheral *) connObj; + for (CBService * service in peripheral.services) { if ([service.UUID.data isEqualToData:serviceId.data]) { for (CBCharacteristic * characteristic in service.characteristics) {