使用 Alamofire 4.0 (Swift 3) 下载文件 [英] Download File Using Alamofire 4.0 (Swift 3)
本文介绍了使用 Alamofire 4.0 (Swift 3) 下载文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在旧版本的 Alamofire 中.这是我下载文件的方式
In older version of Alamofire. This is how I download file
let destinationPath = Alamofire.Request.suggestedDownloadDestination( directory: .documentDirectory, domain: .userDomainMask);
Alamofire.download(.GET, urlString, destination: destinationPath)
.progress { bytesRead, totalBytesRead, totalBytesExpectedToRead in
// print(totalBytesRead)
}
.response { request, response, _, error in
let downloadedFilePath = destinationPath(URL(string: "")!, response!);
NSUserDefaultsHelper.saveURL(downloadedFilePath, key: urlString);
completion(downloadedFilePath, true);
}
但是现在在新版本中,我的代码完全无法使用,Alamofire库中也没有类似的功能.
But now in the new version, my code is completely unusable and there is no similar function in the Alamofire library.
有什么想法吗?
推荐答案
我曾经使用过这样的语句:
I used to use this statements:
let destination = DownloadRequest.suggestedDownloadDestination(for: .documentDirectory)
Alamofire.download(
url,
method: .get,
parameters: parameters,
encoding: JSONEncoding.default,
headers: nil,
to: destination).downloadProgress(closure: { (progress) in
//progress closure
}).response(completionHandler: { (DefaultDownloadResponse) in
//here you able to access the DefaultDownloadResponse
//result closure
})
有关更多详细信息,请阅读 关于迁移到 4.0 的 Alamofire 文档:
For more details read more in Alamofire docs about Migration to 4.0:
这篇关于使用 Alamofire 4.0 (Swift 3) 下载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文