Alamofire请求的进展

时间:2015-11-20 13:04:36

标签: ios swift2 alamofire

是否可以显示

的进度
Alamofire.request(.POST, URL, parameters: parameter, encoding: .JSON)
 .responseJSON { response in
 // Do your stuff
}

我将我的图像/文档作为base64字符串,然后将其转换为移动文件

我可以显示百分比的进度条吗?

我正在使用Alamofire,Swift 2

2 个答案:

答案 0 :(得分:4)

使用Alamofire> = 3.0对Swift 2.x用户进行下载:

{{1}}

答案 1 :(得分:4)

Alamofire 4.0和Swift 4.x

func startDownload(audioUrl:String) -> Void {
    let fileUrl = self.getSaveFileUrl(fileName: audioUrl)
    let destination: DownloadRequest.DownloadFileDestination = { _, _ in
        return (fileUrl, [.removePreviousFile, .createIntermediateDirectories])
    }

    Alamofire.download(audioUrl, to:destination)
        .downloadProgress { (progress) in
            self.surahNameKana.text = (String)(progress.fractionCompleted)
        }
        .responseData { (data) in
            // at this stage , the downloaded data are already saved in fileUrl
            self.surahNameKana.text = "Completed!"
    }
}