问题
Usual I use Alamofire
& Moya/RxSwift
& ObjectMapper
to analysis object
But now add a demand. My app need download file.
I have use
Alamofire.download(urlString, to: destination)
Temporary solved the problem
but It's not elegant.
I want use Moya to Maintain the same network layer.
Can you show a Download Moya"s "TargetType"
回答1:
to use Moya to download files, the key thing is override `
var task:Task{
switch self {
case .download:
return .download(DownloadType.request(DefaultDownloadDestination))
}
}
https://gist.github.com/pandaApe/fac2615f729c9a0cf6bab29700416747
回答2:
@Tony, you have two options according current 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)
来源:https://stackoverflow.com/questions/44237231/how-to-use-moya-to-download-file