Skip to content

Commit b3cf307

Browse files
authored
Merge pull request #1592 from joshavant/add-URLSessionDownloadTask.cancelbyProducingResumeData
Add URLSessionDownloadTask.cancel(byProducingResumeData:)
2 parents d820345 + 96fd921 commit b3cf307

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

Docs/Status.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ There is no _Complete_ status for test coverage because there are always additio
8181
| `URLSessionTask` | Mostly Complete | Incomplete | `cancel()`, `createTransferState(url:)` with streams, and others remain unimplemented |
8282
| `URLSessionDataTask` | Complete | Incomplete | |
8383
| `URLSessionUploadTask` | Complete | None | |
84-
| `URLSessionDownloadTask` | Incomplete | Incomplete | `cancel(byProducingResumeData:)` remains unimplemented |
84+
| `URLSessionDownloadTask` | Incomplete | Incomplete | |
8585
| `URLSessionStreamTask` | Unimplemented | None | |
8686
| `TaskRegistry` | N/A | N/A | For internal use only |
8787
| `TransferState` | N/A | N/A | For internal use only |

Foundation/URLSession/URLSessionTask.swift

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,18 @@ open class URLSessionDownloadTask : URLSessionTask {
428428
* If resume data cannot be created, the completion handler will be
429429
* called with nil resumeData.
430430
*/
431-
open func cancel(byProducingResumeData completionHandler: @escaping (Data?) -> Void) { NSUnimplemented() }
431+
open func cancel(byProducingResumeData completionHandler: @escaping (Data?) -> Void) {
432+
super.cancel()
433+
434+
/*
435+
* In Objective-C, this method relies on an Apple-maintained XPC process
436+
* to manage the bookmarking of partially downloaded data. Therefore, the
437+
* original behavior cannot be directly ported, here.
438+
*
439+
* Instead, we just call the completionHandler directly.
440+
*/
441+
completionHandler(nil)
442+
}
432443
}
433444

434445
/*

0 commit comments

Comments
 (0)