gpt4 book ai didi

swift - 在 MacOS 中下载 Alamofire。看起来不错,进度正常,但没有文件?

转载 作者:行者123 更新时间:2023-11-28 08:25:35 25 4
gpt4 key购买 nike

我通过 cocoapods 添加了 Alamofire,我有一种方法可以下载一个 zip 文件(大约 50Mb)。

虽然下载一切看起来很完美。我可以在 Activity Monitor 中看到为我的应用程序下载了 50Mb,我可以看到进度条在快速移动。但我永远找不到该文件。

现在我将其设置为使用当前目录,但为了以防万一,我尝试了其他目录。我什至通过修改的数据搜索了整个驱动器,但从未找到任何东西。

这是我的代码。

    func downloadAndInstall(){
log.info("Downloading and Installing.....")
displayToUser(content: "Downloading and Installing.....")

let urlString = updatePackageURL //(This is http://xxxx.com/xxxxpackage.zip)
let fileManager = FileManager.default
currentDir = fileManager.currentDirectoryPath
let fileURL: URL = URL(string: currentDir + "/package.zip")!
let destination: DownloadRequest.DownloadFileDestination = { _, _ in (fileURL, []) }
log.info("FILEURL: \(fileURL)")
var progressValues: [Double] = []
var response: DefaultDownloadResponse?

Alamofire.download(urlString, to: destination)
.downloadProgress { progress in
progressValues.append(progress.fractionCompleted)
log.info("Latest Progress Value: \(progress.fractionCompleted)")
self.progBar.doubleValue = progress.fractionCompleted
}
.response { resp in
response = resp
if progressValues.last != 1.0 {
//backout of the process, something went wrong
log.debug("Something went wrong downloading the file. Close and try again.")
self.displayToUser(content: "Something went wrong downloading the file. Close and try again.")
self.exitpoorly()
}
else{
log.info("Download Finished")
self.displayToUser(content: "Download Finished")
self.extractpackage()
}
}

var previousProgress: Double = progressValues.first ?? 0.0

for progress in progressValues {
previousProgress = progress
}

if let lastProgressValue = progressValues.last {
log.info("Current Download Value: \(lastProgressValue, 1.0)")
} else {
//Fail
}
}

最佳答案

我建议检查是否有任何错误,例如:

Alamofire.download(urlString, to: destination)
.downloadProgress { progress in
...
}
.response { response in
guard response.error == nil else {
//backout of the process, something went wrong
log.debug("Something went wrong downloading the file. Close and try again.")
log.debug(response.error!.localizedDescription)
...
self.exitpoorly()
return
}

log.info("Download Finished")
...
}

也许该应用程序已被沙盒化,或者您可能没有该文件夹的权限。没有看到错误很难说。

关于swift - 在 MacOS 中下载 Alamofire。看起来不错,进度正常,但没有文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40113961/

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