<!--
{
  "availability" : [
    "macOS: 15.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "CoreHID",
  "identifier" : "/documentation/CoreHID/HIDDeviceManager/monitorNotifications(matchingCriteria:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Core HID"
    ],
    "preciseIdentifier" : "s:7CoreHID16HIDDeviceManagerC20monitorNotifications16matchingCriteriaScsyAC12NotificationOs5Error_pGSayAC014DeviceMatchingH0VG_tF"
  },
  "title" : "monitorNotifications(matchingCriteria:)"
}
-->

# monitorNotifications(matchingCriteria:)

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

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

## Parameters

`matchingCriteria`

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

## 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:

```swift
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
    }
}
```

> Throws: ``doc://com.apple.CoreHID/documentation/CoreHID/HIDDeviceError`` if there is an issue with setup.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)