<!--
{
  "availability" : [
    "iOS: 7.0.0 -",
    "iPadOS: 7.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.9.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/URLSessionDownloadTask/cancel(byProducingResumeData:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSURLSessionDownloadTask(im)cancelByProducingResumeData:"
  },
  "title" : "cancel(byProducingResumeData:)"
}
-->

# cancel(byProducingResumeData:)

Cancels a download and calls a callback with resume data for later use.

```
func cancel(byProducingResumeData completionHandler: @escaping @Sendable (Data?) -> Void)
```

## Parameters

`completionHandler`

A completion handler that is called when the download has been successfully canceled.

    If the download is resumable, the completion handler is provided with a     `resumeData`     object. Your app can later pass this object to a session’s [`downloadTask(withResumeData:)`](/documentation/Foundation/URLSession/downloadTask(withResumeData:))     or [`downloadTask(withResumeData:completionHandler:)`](/documentation/Foundation/URLSession/downloadTask(withResumeData:completionHandler:))     method to create a new task that resumes the download where it left off.

    This block is not guaranteed to execute in a particular thread context. As such, you may want specify an appropriate dispatch queue in which to perform any work.

## Discussion

A download can be resumed only if the following conditions are met:

- The resource has not changed since you first requested it
- The task is an HTTP or HTTPS `GET` request
- The server provides either the `ETag` or `Last-Modified` header (or both) in its response
- The server supports byte-range requests
- The temporary file hasn’t been deleted by the system in response to disk space pressure

---

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)