在阿拉莫菲尔的旧版本中.这就是我下载文件的方式

    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库中也没有类似的函数.

有什么 idea 吗?

推荐答案

我曾经用过这样的说法:

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 docs about Migration to 4.0:

Swift相关问答推荐

如何更新Square Order?

阻塞(受CPU限制的)任务的异步功能?

带DispatchSourceTimer的定时器

是否可以将具有关联值的枚举强制转换为其类型与关联值匹配的变量?

解码器是否需要具有密钥的外部数据表示?

使用 @resultBuilder 的通用 buildList 函数

在SwiftUI中如何预览嵌套的ScrollView,以避免触发可刷新修饰符

在 Swift 中将异步任务包装到 DispatchWorkItem 中以使其可取消?

本地对象的异步/等待引用捕获总是安全的还是理论上不安全?

deinitialize() 与 deallocate()

为什么 NumberFormatter 在 Swift 中将 19,999,999,999,999,999 格式化为 20,000,000,000,000,000?

UIButton 配置不更新按钮标题

Swift 全局函数列表

SwiftUI 视图的默认成员初始化器 VS 自定义初始化器

Vapor 4,如何按外键过滤?

快速在 LLDB 中使用 po

如何快速识别字符串中的大写和小写字符?

如何使用 Swift 枚举作为字典键? (符合 Equatable)

UISearchbar TextField 的高度可以修改吗?

迭代 Firebase 中的子快照