From b7dc630d572e900fd9b570e4cc7f5d58e2bc7d76 Mon Sep 17 00:00:00 2001 From: Nathan Schmidt Date: Tue, 6 Jan 2026 12:58:43 -0800 Subject: [PATCH] Add filter to paired device retrieval --- Sources/ActorCoreBluetooth/BluetoothCentral.swift | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Sources/ActorCoreBluetooth/BluetoothCentral.swift b/Sources/ActorCoreBluetooth/BluetoothCentral.swift index 3d7b6ea..134f413 100644 --- a/Sources/ActorCoreBluetooth/BluetoothCentral.swift +++ b/Sources/ActorCoreBluetooth/BluetoothCentral.swift @@ -441,7 +441,8 @@ public final class BluetoothCentral { /// This is useful for peripherals connected by other apps or the system public func retrieveConnectedPeripherals( withServices services: [String], - timeout: TimeInterval? = nil + timeout: TimeInterval? = nil, + filter: ((DiscoveredPeripheral) -> Bool)? = nil ) async throws -> [ConnectedPeripheral] { try await ensureCentralManagerInitialized() @@ -473,6 +474,13 @@ public final class BluetoothCentral { var connectedPeripherals: [ConnectedPeripheral] = [] for cbPeripheral in cbPeripherals { + if filter != nil && filter!(DiscoveredPeripheral(cbPeripheral: cbPeripheral, advertisementData: [:], rssi: 0)) == false { + logger?.centralDebug("Skipping retrieved peripheral not matching filter", context: [ + "peripheralName": cbPeripheral.name ?? "Unknown", + "peripheralID": cbPeripheral.identifier.uuidString + ]) + continue + } do { let connected = try await connectToRetrievedPeripheral( cbPeripheral,