// Ниже приведен код для загрузки файла с URL-адреса, теперь, когда мой donwload перехвачен. Я хочу возобновить мой donwnload снова с данных, которые я скачал.
func downloadPDFPacket(PacketUrl : String,PacketName : String,AgendaID : Int,MeetingID : Int,progressBar:UIProgressView,lblDownload:UILabel){
var checkCompleted = false
Alamofire.request("\(PacketUrl)").downloadProgress(closure : { (progress) in
let x = progress.fractionCompleted
let y = Double(round(10*x)/10)
progressBar.progress = Float(y)
lblDownload.text = "Downloading...\n\(y*100) %"
if (y*100 == 100.0){
checkCompleted = true
}else{
checkCompleted = false
}
}).responseData{ (response) in
var statusCode = response.response?.statusCode
switch response.result {
case .success:
if statusCode == 200{
if checkCompleted == true{
//File name to save into the local storage
var strPacketName = PacketName.replacingOccurrences(of: " ", with: "")
strPacketName = strPacketName.replacingOccurrences(of: "/", with: "")
let paths = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true) as Array
let documentDirectory = paths[0] as NSString
let path = documentDirectory.appendingPathComponent("\(strPacketName)\("_")\(UserDefaults.standard.getUserID())\("_")\(AgendaID)\(".pdf")")
let fileManager = FileManager.default
if(!fileManager.fileExists(atPath: path)){
do {
let val = try response.data?.write(to: URL(fileURLWithPath: path), options: .atomic)
DispatchQueue.main.async {
//OnSuccess
self.onComplete?("Success")
self.updateAgendaMeetingDetailCount(AgendaId: AgendaID, YesOrNo: 1)
self.updateMeetingDownloadPacketCount(MeetingId: "\(MeetingID)")
}
} catch {
}
}else{
//If File Already exits
self.onComplete?("Already Exits")
self.updateAgendaMeetingDetailCount(AgendaId: AgendaID, YesOrNo: 1)
self.updateMeetingDownloadPacketCount(MeetingId: "\(MeetingID)")
}
}else{
self.onComplete?("Error Downloading")
}
}else if statusCode == 404{
self.onComplete?(StringMessages.error404)
}else if statusCode == 401{
self.onComplete?(StringMessages.error404)
}else if statusCode == 500{
self.onComplete?(StringMessages.error404)
}else{
if statusCode == -1001{
self.onComplete?(StringMessages.timeout)
}
}
// Ошибка при Загрузка дела 1004 *