使用Alamofire 4.0下载文件(Swift 3) [英] Download File Using Alamofire 4.0 (Swift 3)

查看:2854
本文介绍了使用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)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆