<!--
{
  "availability" : [
    "iOS: 2.0.0 - 27.0.0",
    "iPadOS: 2.0.0 - 27.0.0",
    "macCatalyst: 13.1.0 - 27.0.0",
    "macOS: 10.4.0 - 27.0.0",
    "tvOS: 9.0.0 - 27.0.0",
    "visionOS: 1.0.0 - 27.0.0"
  ],
  "documentType" : "symbol",
  "framework" : "CFNetwork",
  "identifier" : "/documentation/CFNetwork/CFNetServiceMonitorCreate(_:_:_:_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Function",
  "symbol" : {
    "kind" : "Function",
    "modules" : [
      "CFNetwork"
    ],
    "preciseIdentifier" : "c:@F@CFNetServiceMonitorCreate"
  },
  "title" : "CFNetServiceMonitorCreate(_:_:_:_:)"
}
-->

# CFNetServiceMonitorCreate(_:_:_:_:)

Creates an instance of a NetServiceMonitor object that watches for record changes.

```
func CFNetServiceMonitorCreate(_ alloc: CFAllocator?, _ theService: CFNetService, _ clientCB: CFNetServiceMonitorClientCallBack, _ clientContext: UnsafeMutablePointer<CFNetServiceClientContext>) -> Unmanaged<CFNetServiceMonitor>
```

## Parameters

`alloc`

The allocator to use to allocate memory for the new object. Pass `NULL` or <doc://com.apple.documentation/documentation/CoreFoundation/kCFAllocatorDefault> to use the current default allocator.

`theService`

CFNetService to be monitored.

`clientCB`

Pointer to callback function that is to be called when a record associated with `theService` changes; cannot be `NULL`.

`clientContext`

Pointer to user-defined contextual information that is to be passed to the callback specified by `clientCB` when the callback is called; cannot be `NULL`. For details, see [`CFNetServiceClientContext`](/documentation/CFNetwork/CFNetServiceClientContext).

## Return Value

A new instance of a CFNetServiceMonitor, or `NULL` if the monitor could not be created. Ownership follows the [The Create Rule](https://developer.apple.com/library/archive/documentation/CoreFoundation/Conceptual/CFMemoryMgmt/Concepts/Ownership.html#//apple_ref/doc/uid/20001148-103029).

## Discussion

This function creates a CFNetServiceMonitor that watches for changes in records associated with `theService`.

If the CFNetServiceMonitor is to run in asynchronous mode, call [`CFNetServiceMonitorScheduleWithRunLoop(_:_:_:)`](/documentation/CFNetwork/CFNetServiceMonitorScheduleWithRunLoop(_:_:_:)) to schedule the monitor on a run loop. Then call [`CFNetServiceMonitorStart(_:_:_:)`](/documentation/CFNetwork/CFNetServiceMonitorStart(_:_:_:)) to start monitoring. When a change occurs, the callback function specified by `clientCB` will be called. For details, see [`CFNetServiceMonitorClientCallBack`](/documentation/CFNetwork/CFNetServiceMonitorClientCallBack).

If the CFNetServiceMonitor is to run in synchronous mode, call [`CFNetServiceMonitorStart(_:_:_:)`](/documentation/CFNetwork/CFNetServiceMonitorStart(_:_:_:)).

To stop a monitor that is running in asynchronous mode, call [`CFNetServiceMonitorStop(_:_:)`](/documentation/CFNetwork/CFNetServiceMonitorStop(_:_:)) and [`CFNetServiceMonitorUnscheduleFromRunLoop(_:_:_:)`](/documentation/CFNetwork/CFNetServiceMonitorUnscheduleFromRunLoop(_:_:_:)).

To stop a monitor that is running in synchronous mode, call [`CFNetServiceMonitorStop(_:_:)`](/documentation/CFNetwork/CFNetServiceMonitorStop(_:_:)).

If you no longer need to monitor record changes, call [`CFNetServiceMonitorStop(_:_:)`](/documentation/CFNetwork/CFNetServiceMonitorStop(_:_:)) to stop the monitor and then call [`CFNetServiceMonitorInvalidate(_:)`](/documentation/CFNetwork/CFNetServiceMonitorInvalidate(_:))to invalidate the monitor so it cannot be used again. Then call `CFRelease` to release the memory associated with CFNetServiceMonitorRef.

### Special Considerations

This function is thread safe.

---

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)