我想从我的API下载文件中的数据(令牌需要),actualy,我有这样的代码:Alamofire - 下载文件
let headers = [
"token": getToken()
]
Alamofire.download("http://API-URL.com/data/chapter/\(chapterID)/file", headers: headers)
.downloadProgress { progress in
print("Download Progress: \(progress.fractionCompleted)")
}
.responseData { response in
print(response.result.value)
}
的文件下载,我可以看到它在tmp目录模拟器, 进度事件被解雇过,但结局下载后,临时文件被删除,response.result.value
是nil
我怎么能在文件与头的请求和事件进展下载数据?
编辑我:
response.result.error
给我:
Alamofire.AFError.responseSerializationFailed(Alamofire.AFError.ResponseSerializationFailureReason.inputFileReadFailed(文件:///用户/ us001 /库/开发/ CoreSimulator /设备/ FABD2181-9702-4599-8D2D-7B25E2128F4A /数据/容器/数据/应用/ C63C4524-6A53-410B-BE3E-66B5E6F6D069/TMP/CFNetworkDownload_zyr0xF.tmp
编辑II:
通过Alamofire.request
改变Alamofire.download
删除错误,给我的数据大小response.result.value
但文件仍然被删除
它返回数据大小还是数据? –