diff --git a/internal/platform/implementation/apple/ble_medium.mm b/internal/platform/implementation/apple/ble_medium.mm index f7bb3b0a4e..3f8d4e7690 100644 --- a/internal/platform/implementation/apple/ble_medium.mm +++ b/internal/platform/implementation/apple/ble_medium.mm @@ -127,12 +127,17 @@ data.service_data[CPPUUIDFromObjC(key)] = ByteArrayFromNSData(serviceData[key]); } - // Add the peripheral to the map if we haven't discovered it yet. + // Always add the peripheral to the map. We may have discovered it before, but it's possible that + // the MAC address has rotated, so we should always hold on to the latest peripheral object. + // See: b/375176623 auto ble_peripheral = std::make_unique(peripheral); auto unique_id = ble_peripheral->GetUniqueId(); auto it = peripherals_.find(unique_id); if (it == peripherals_.end()) { + peripherals_[unique_id] = std::move(ble_peripheral); + } else { + peripherals_[unique_id]->peripheral_ = peripheral; } if (scanning_cb_.advertisement_found_cb) { scanning_cb_.advertisement_found_cb(*peripherals_[unique_id], data); diff --git a/internal/platform/implementation/apple/ble_peripheral.h b/internal/platform/implementation/apple/ble_peripheral.h index a1d23680bf..6dada817de 100644 --- a/internal/platform/implementation/apple/ble_peripheral.h +++ b/internal/platform/implementation/apple/ble_peripheral.h @@ -75,8 +75,9 @@ class BlePeripheral : public api::ble_v2::BlePeripheral { // Returns the CoreBluetooth peripheral object. id GetPeripheral() const; - private: id peripheral_; + + private: api::ble_v2::BlePeripheral::UniqueId unique_id_; };