gpt4 book ai didi

ios - 如何检查完成处理程序 block 中 NSURLSessionDownloadTask 的状态?

转载 作者:行者123 更新时间:2023-11-28 09:18:28 24 4
gpt4 key购买 nike

假设我创建了一个 NSURLSessionDownloadTask:

let downloadTask = session.downloadTaskWithURL(URL, completionHandler: { location, response, error in
...
}

如果我稍后在那个 downloadTask 上调用 cancel(),它仍然会调用完成处理程序,对吗?我想检查下载任务的状态是否为 Cancelling,这样它就不会试图弄乱下载的图像,在这种情况下不会有。

我无法检查下载任务本身的状态,因为它在变量的创建过程中。

最佳答案

检查完成处理程序中的error 参数。或者检查 NSURLSessionTaskstate 属性。如果它等于 'NSURLSessionTaskState.Completed' 那么下载任务不会被取消。文档说:

The task has completed (without being canceled), and the task's delegate receives no further callbacks. If the task completed successfully, the task’s error property is nil. Otherwise, it provides an error object that tells what went wrong. A task in this state is not subject to timeouts.

关于ios - 如何检查完成处理程序 block 中 NSURLSessionDownloadTask 的状态?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26406080/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com