monitorNotifications(matchingCriteria:)
Creates an asynchronous stream that receives notifications for devices of interest.
Declaration
func monitorNotifications(matchingCriteria: [HIDDeviceManager.DeviceMatchingCriteria]) -> AsyncThrowingStream<HIDDeviceManager.Notification, any Error>Parameters
- matchingCriteria:
A set of Devicematchingcriteria for matching devices connected to the system. Criteria are considered separately, if one set is specified that matches one device, with a second set that matches five other devices, all six devices are matched. Matched devices result in a Devicematched(_:) notification. Matched devices are ready for connections using Hiddeviceclient until a Deviceremoved(_:) notification is received for the device.
Mentioned in
Return Value
An asynchronous stream that receives notifications.
Discussion
Notifications come in asynchronously from the manager at arbitrary times when relevant events occur.
Example usage:
let searchCriteria = HIDDeviceManager.DeviceMatchingCriteria(primaryUsage: .genericDesktop(.keyboard), isBuiltIn: false)
for await notification in await manager.monitorNotifications(matchingCriteria: [searchCriteria]) {
switch notification {
case .deviceMatched(let deviceReference):
client = HIDDeviceClient(deviceReference: deviceReference)
break
case .deviceRemoved(_):
continue
}
}