Alamofire.download(.POST,invoice.url,parameters:params,destination: { (url,response) -> NSURL in let pathComponent = response.suggestedfilename let fileManager = NSfileManager.defaultManager() let directoryURL = fileManager.URLsForDirectory(.documentDirectory,inDomains: .UserDomainMask)[0] let fileUrl = directoryURL.URLByAppendingPathComponent(pathComponent) return fileUrl }) .progress { bytesRead,totalBytesRead,totalBytesExpectedToRead in print(totalBytesRead) dispatch_async(dispatch_get_main_queue()) { let progress = Double(totalBytesRead) / Double(totalBytesExpectedToRead) completionHandler(progress,nil) } } .responseString { response in print(response.result.error) completionHandler(nil,response.result.error) }在Swift 3中它就是这样的.
let parameters: Parameters = ["foo": "bar"]let destination: DownloadRequest.DownloadfileDestination = { _,_ in let pathComponent = "yourfilename" let documentsURL = fileManager.default.urls(for: .documentDirectory,in: .userDomainMask)[0] let fileURL = documentsURL.appendpathComponent(pathComponent) return (fileURL,[.removePrevIoUsfile,.createIntermediateDirectorIEs])}Alamofire.download(urlString,method: .get,parameters: parameters,enCoding: JsONEnCoding.default,to: destination) .downloadProgress(queue: dispatchQueue.global(qos: .utility)) { progress in print("Progress: \(progress.fractionCompleted)") } .valIDate { request,response,temporaryURL,destinationURL in // Custom evaluation closure Now includes file URLs (allows you to parse out error messages if necessary) return .success } .responseJsON { response in deBUGPrint(response) print(response.temporaryURL) print(response.destinationURL) }
有关详细信息,请查看Alamofire Documentation
或Alamofire 4.0 Migration Guide
.
以上是内存溢出为你收集整理的swift3 – 设置Alamofire自定义目标文件名,而不是在Swift 3.0中使用suggestDownloadDestination全部内容,希望文章能够帮你解决swift3 – 设置Alamofire自定义目标文件名,而不是在Swift 3.0中使用suggestDownloadDestination所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)