allDevices(matching:)
Provides a snapshot of all the paired devices known to your app.
Declaration
static func allDevices(matching: Predicate<WAPairedDevice>) -> WAPairedDevice.DevicesSequenceParameters
- matching:
The predicate that filters the devices. The system only provides updates for devices matching this predicate.
Return Value
A new WAPairedDevice.DevicesSequence that returns WAPairedDevice.Devices elements holding a snapshot of the currently paired devices known to your app.
Discussion
This method gets an AsyncSequence that provides snapshots of all WAPairedDevice.Devices currently paired and known to your app that match the provided predicate, and provides updates when the snapshot of WAPairedDevice.Devices matching that predicate changes. The sequence outputs an empty dictionary if there are no paired devices matching the predicate that are known to your app, or if a person removes all of your app’s matching paired devices.
You can select the set of Devices matching a filter from this property using the code below:
let filter = #Predicate<WAPairedDevice> { $0.pairingInfo?.vendorName.starts(with: "Example Inc") ?? false }
// Get a snapshot of all paired devices at the current moment.
guard let devices = try await WAPairedDevice.allDevices(matching:filter).current() { return }
// Get a snapshot of all paired devices at the current moment, and get a new snapshot each time a device is added, changed, or removed.
for try await devices in WAPairedDevice.allDevices(matching:filter) {
// Process update.
}