swift - 使用 Alamofire 4 下载 MP4 文件,同时附加自定义 header

标签 swift http swift3 alamofire

我正在尝试使用以下代码成功下载 MP4 数据:

private func downloadVideo(cat: String){
    DispatchQueue.global(qos: .background).async {
        let destination: DownloadRequest.DownloadFileDestination = { _, _ in
            var documentsURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0]

            let milPath = "VID.mp4"
            documentsURL.appendPathComponent(milPath)
            return (documentsURL, [.removePreviousFile])
        }

        Alamofire.download(self.url, to: destination).response { response in
            if response.destinationURL != nil {
                print(response.destinationURL!)
                let path = (response.destinationURL?.absoluteString)!
                self.uVid[cat] = path
                //self.playVideo(path);
                DispatchQueue.main.async {
                    let uim = self.uBlur[cat]
                    self.disappearView(im : uim!)
                }
            }
        }
    }
}

但是,在向我提供正确的 mp4 数据的同时,我无法附加服务器所需的自定义 header 。有人可以构建一个示例/建议,说明我如何在传递自定义 header 时调用 Alamofire.download() 函数吗?

最佳答案

我设法找到了这个问题的解决方案。

简单地在 self.ur,,to:destination 之间添加头数组

关于swift - 使用 Alamofire 4 下载 MP4 文件,同时附加自定义 header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42629590/

相关文章:

ios - 移至自定义 UItableViewCell 中的下一个 UItextfield(具有多个部分的 Tableview)

SwiftUI LazyHGrid 行居中

ios - 如何多次使用 UIPickerView 和 TextField ?

swift - 使用 Swift 反转双链表

php - 通过 PHP 或 Apache 从服务器端上传 HTTP 文件

在 Swift 中比较指向 C 函数的指针

ios - 在 Swift 中子类化 Objective-C 类

休息 API : Should we use PUT or DELETE to update resource partially?

ios - 使用 http 和 https 移动网络服务

swift - 类型 'String' 的值在 Swift 3 中没有成员 'stringByRemovingPercentEncoding