gpt4 book ai didi

ios - 如何暂停 NSURLSessionDownloadTask?

转载 作者:可可西里 更新时间:2023-11-01 00:12:07 26 4
gpt4 key购买 nike

这就是我使用 NSURLSessionDownloadTask 的方式:

    let sessionConfiguration = NSURLSessionConfiguration.defaultSessionConfiguration()
let sessionManager = AFURLSessionManager(sessionConfiguration: sessionConfiguration)

if let url = NSURL(string: URLString) {

let request = NSURLRequest(URL: url)
let sessionDownloadTask = sessionManager.downloadTaskWithRequest(request, progress: nil, destination: { (url, response) -> NSURL in

self.createDirectoryAtPath(destinationPath)

return destinationPath.URLByAppendingPathComponent(fileName)

}, completionHandler: { response, url, error in

completionBlock(error)
})

sessionDownloadTask.resume()
}

我知道我可以调用 sessionDownloadTask.cancel()sessionDownloadTask.resume(),但我需要在那里调用 .pause(),然后 .resume() 继续下载。可能吗?

最佳答案

NSURLSessionTask的这个方法

.suspend()

文档

A task, while suspended, produces no network traffic and is not subject to timeouts. A download task can continue transferring data at a later time. All other tasks must start over when resumed.

关于ios - 如何暂停 NSURLSessionDownloadTask?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34261309/

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