这是我的代码,它下载文件但未将文件放置在图库或文件夹中:
let destination: DownloadRequest.DownloadFileDestination = { _, _ in
let documentsURL:NSURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first! as NSURL
print("***documentURL: ",documentsURL)
let fileURL = documentsURL.appendingPathComponent("\(ind).pdf")
print("***fileURL: ",fileURL ?? "")
return (fileURL!,[.removePreviousFile, .createIntermediateDirectories])
}
let parameters: Parameters = [:]
Alamofire.download(urlString.addingPercentEncoding(withAllowedCharacters:NSCharacterSet.urlQueryAllowed)!,method:.get,parameters:parameters,encoding:JSONEncoding.default,headers:["Authorization": "\(ParentService.AUTHTOCK)"],to: destination).downloadProgress(closure: { (prog) in
hud.progress = Float(prog.fractionCompleted)
}).response { response in
//print(response)
hud.hide(animated: true)
if response.error == nil, let filePath = response.destinationURL?.path {
print("mmmm",filePath)
self.fileLocalURLDict[ind] = filePath
DispatchQueue.main.async {
let urlString:String! = self.fileLocalURLDict[ind]
let fileURL = URL(fileURLWithPath: urlString)
let request = URLRequest(url: fileURL)
self.webView.loadRequest(request)
}
}
else
{
print(response.error)
}
}
//--1.--//
// }
}