How to use Moya to download file

非 Y 不嫁゛ 提交于 2020-08-03 03:32:28

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!