gpt4 book ai didi

swift - Alamofire:缓存下载到 Documents 文件夹的大文件

转载 作者:搜寻专家 更新时间:2023-10-31 08:17:38 27 4
gpt4 key购买 nike

我使用这段代码将MP3文件下载到文档目录:

let destination = DownloadRequest.suggestedDownloadDestination(for: .documentDirectory)
Alamofire.download(theUrl!, to:destination).response { response in
// stuff
}.downloadProgress { progress in
// Stuff
}

文件下载正常,但如果我关闭应用程序并再次启动它,下载将从 0 重新开始。我想要的是立即缓存和获取文件。我对 Alamofire 的理解是文件被下载到一个临时文件夹,然后移动到 Documents 文件夹,这是导致缓存没有发生的原因吗?

非常感谢

最佳答案

请按顺序查看以下引用资料:
1. https://github.com/Alamofire/Alamofire/issues/1104
2. https://github.com/Alamofire/Alamofire#resuming-a-download
3. https://stackoverflow.com/a/39347461/3549695

总结:
您需要在应用退出前使用request.cancel() API 生成resumeData。
然后,您将 resume API 与 resumeData 结合使用,以在应用重新启动时恢复请求。
不能保证它会一直有效。如果失败,它仍然会从 0 重新启动。

在上面的引用文献 (2) 中提到了 iOS 10 的问题,导致它无法正常工作。但是 StackOverflow 上的更新(引用文献 3)有报告说它已在 iOS 10.2 中得到修复

关于swift - Alamofire:缓存下载到 Documents 文件夹的大文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44077080/

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