Swift 在MacOS中下载Alamofire。看起来不错,进展正常,但没有文件?
我通过cocoapods添加了Alamofire,我有一个方法可以下载一个zip文件(大约50Mb) 虽然下载一切看起来都很完美。我可以在Activity Monitor中看到我的应用下载了50Mb,我可以看到progressbar横穿。但是我永远找不到文件 现在我已经将它设置为使用当前目录,但为了以防万一,我尝试了其他目录。我甚至搜索了整个驱动器的数据修改,从来没有找到任何东西 这是我的密码Swift 在MacOS中下载Alamofire。看起来不错,进展正常,但没有文件?,swift,alamofire,Swift,Alamofire,我通过cocoapods添加了Alamofire,我有一个方法可以下载一个zip文件(大约50Mb) 虽然下载一切看起来都很完美。我可以在Activity Monitor中看到我的应用下载了50Mb,我可以看到progressbar横穿。但是我永远找不到文件 现在我已经将它设置为使用当前目录,但为了以防万一,我尝试了其他目录。我甚至搜索了整个驱动器的数据修改,从来没有找到任何东西 这是我的密码 func downloadAndInstall(){ log.info("Do
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")
...
}
可能应用程序已沙盒,或者您没有该文件夹的权限。很难说没有看到错误。我建议检查任何错误,例如:
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")
...
}
可能应用程序已沙盒,或者您没有该文件夹的权限。很难说没有看到错误。我发现文件URL有问题。。。告诉我我需要看什么。谢谢原来我的文件URL有问题。。。告诉我我需要看什么。谢谢