使用Alamofire 4.0下载文件(Swift 3)

编程入门 行业动态 更新时间:2024-10-27 14:20:26
本文介绍了使用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 })

详情请阅读更多在 Alamofire关于迁移到4.0的文档:

更多推荐

使用Alamofire 4.0下载文件(Swift 3)

本文发布于:2023-11-26 06:04:41,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1632932.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件   Alamofire   Swift

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!