在旧版本的 Alamofire 中。这是我下载文件的方式
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库中也没有类似的功能。
有什么想法吗?
最佳答案
我曾经使用过这个语句:
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
})
有关更多详细信息,请阅读 Alamofire docs about Migration to 4.0 :
关于ios - 使用 Alamofire 4.0 (Swift 3) 下载文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39912905/