4

通常我使用Alamofire& Moya/RxSwift&ObjectMapper来分析对象但现在添加一个需求。我的应用需要下载文件。

我有用

Alamofire.download(urlString, to: destination) 

临时解决了问题

但这并不优雅。

我想使用 Moya 来维护相同的网络层。

你能显示一个下载 Moya 的“TargetType”吗

4

2 回答 2

2

使用Moya下载文件,关键是override`

var task:Task{
    switch self {
        case .download:
        return .download(DownloadType.request(DefaultDownloadDestination))
   }
}

https://gist.github.com/pandaApe/fac2615f729c9a0cf6bab29700416747

于 2017-07-27T08:56:15.000 回答
1

@Tony,根据当前的 Moya API,您有两个选择。

/// A file download task to a destination.
case downloadDestination(DownloadDestination)

/// A file download task to a destination with extra parameters using the given encoding.
case downloadParameters(parameters: [String: Any], encoding: ParameterEncoding, destination: DownloadDestination)
于 2018-11-12T09:10:22.777 回答