<!--
{
  "availability" : [
    "iOS: 2.0.0 - 27.0.0",
    "iPadOS: 2.0.0 - 27.0.0",
    "macCatalyst: 13.1.0 - 27.0.0",
    "macOS: 10.2.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/CFNetServiceCancel(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Function",
  "symbol" : {
    "kind" : "Function",
    "modules" : [
      "CFNetwork"
    ],
    "preciseIdentifier" : "c:@F@CFNetServiceCancel"
  },
  "title" : "CFNetServiceCancel(_:)"
}
-->

# CFNetServiceCancel(_:)

Cancels a service registration or a service resolution.

```
func CFNetServiceCancel(_ theService: CFNetService)
```

## Parameters

`theService`

The CFNetService, obtained by previously calling [`CFNetServiceCreate(_:_:_:_:_:)`](/documentation/CFNetwork/CFNetServiceCreate(_:_:_:_:_:)), for which a registration or a resolution is to be canceled.

## Discussion

This function cancels service registrations, started by [`CFNetServiceRegister`](/documentation/CFNetwork/CFNetServiceRegister), thereby making the service unavailable. It also cancels service resolutions, started by [`CFNetServiceResolve`](/documentation/CFNetwork/CFNetServiceResolve).

If you are shutting down an asynchronous service, you should first call [`CFNetServiceUnscheduleFromRunLoop(_:_:_:)`](/documentation/CFNetwork/CFNetServiceUnscheduleFromRunLoop(_:_:_:)) and [`CFNetServiceSetClient(_:_:_:)`](/documentation/CFNetwork/CFNetServiceSetClient(_:_:_:)) with `clientCB` set to `NULL.` Then call this function.

If you are shutting down a synchronous service, call this function from another thread.

This function also cancels service resolutions. You would want to cancel a service resolution if your callback function has received an IP address that you’ve successfully used to connect to the service. In addition, you might want to cancel a service resolution if the resolution is taking longer than a user would want to wait or if the user canceled the operation.

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