gpt4 book ai didi

ios - 使用 alamofire 下载不完整的文件

转载 作者:行者123 更新时间:2023-11-30 13:59:56 24 4
gpt4 key购买 nike

我有 60 个远程文件(图像)的列表,我想下载所有这些文件,但是当我尝试在此处下载 15 个图像时,我的代码

    let destination = Alamofire.Request.suggestedDownloadDestination(directory: .DocumentDirectory, domain: .UserDomainMask)

for var i = 1; i < 61; i++ {

Alamofire.download(.GET, "https://domain.com/folder/\(i).jpg", destination: destination)
.progress { bytesRead, totalBytesRead, totalBytesExpectedToRead in
dispatch_async(dispatch_get_main_queue()) {
print("Total bytes read on main queue: \(totalBytesRead)")
}
}
.response { _, _, _, error in
if let error = error {
print("Failed with error: \(error)")
} else {
print("Downloaded file successfully")
}
}

}

有什么想法吗???

最佳答案

func doDownload(i:int)
{
if(i > 60)
{
return;
}
let destination = Alamofire.Request.suggestedDownloadDestination(directory: .DocumentDirectory, domain: .UserDomainMask)

Alamofire.download(.GET, "https://domain.com/folder/\(i).jpg", destination: destination)
.progress { bytesRead, totalBytesRead, totalBytesExpectedToRead in
dispatch_async(dispatch_get_main_queue()) {
print("Total bytes read on main queue: \(totalBytesRead)")
}
}
.response { _, _, _, error in
if let error = error {
print("Failed with error: \(error)")
} else {
print("Downloaded file successfully")
doDownload(i + 1); //If you only want to download on success do it here
}
//Otherwise doDownload(i + 1)here;
}
}

关于ios - 使用 alamofire 下载不完整的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33114517/

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