---
title: "monitorNotifications(matchingCriteria:)"
framework: corehid
role: symbol
role_heading: Instance Method
path: "corehid/hiddevicemanager/monitornotifications(matchingcriteria:)"
---

# monitorNotifications(matchingCriteria:)

Creates an asynchronous stream that receives notifications for devices of interest.

## Declaration

```swift
func monitorNotifications(matchingCriteria: [HIDDeviceManager.DeviceMatchingCriteria]) -> AsyncThrowingStream<HIDDeviceManager.Notification, any Error>
```

## Parameters

- `matchingCriteria`: A set of doc://com.apple.CoreHID/documentation/CoreHID/HIDDeviceManager/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 doc://com.apple.CoreHID/documentation/CoreHID/HIDDeviceManager/Notification/deviceMatched(_:) notification. Matched devices are ready for connections using doc://com.apple.CoreHID/documentation/CoreHID/HIDDeviceClient until a doc://com.apple.CoreHID/documentation/CoreHID/HIDDeviceManager/Notification/deviceRemoved(_:) notification is received for the device.

## Mentioned in

Communicating with human interface devices

## Return Value

Return Value An asynchronous stream that receives notifications.

## Discussion

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     } } note: HIDDeviceError if there is an issue with setup.

## See Also

### Monitor device notifications

- [HIDDeviceManager.Notification](corehid/hiddevicemanager/notification.md)
