iOS开发之swift网络请求框架Alamofire

1.下载文件显示进度
A.任何DownloadRequest都可以使用downloadProgress API得到下载进度。

Alamofire.download("https://httpbin.org/image/png")
    .downloadProgress { progress in
        print("Download Progress: \(progress.fractionCompleted)")
    }
    .responseData { response in
        if let data = response.result.value {
            let image = UIImage(data: data)
        }
    }

B.queue参数定义了下载进度闭包在哪个DispatchQueue调用。

let utilityQueue = DispatchQueue.global(qos: .utility)

Alamofire.download("https://httpbin.org/image/png")
    .downloadProgress(queue: utilityQueue) { progress in
        print("Download Progress: \(progress.fractionCompleted)")
    }
    .responseData { response in
        if let data = response.result.value {
            let image = UIImage(data: data)
        }
    }

你可能感兴趣的:(iOS开发之swift网络请求框架Alamofire)