В alomofire 3.5 следующий код работал хорошоСкачать аудио файл, используя SessionManager в Alamofire 4 в Swift 3
self.sessionManager.download(.GET, AppConstants.musicFileURL + musicFilename, destination: { (url, response) -> NSURL in
let fileManager = NSFileManager.defaultManager()
let directoryURL = fileManager.URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)[0]
let fileUrl = directoryURL.URLByAppendingPathComponent(musicFilename)
return fileUrl
})
.progress { bytesRead, totalBytesRead, totalBytesExpectedToRead in
self.percentageDownloaded[exhibitId]![artworkId] = (Double(totalBytesRead) ,Double(totalBytesExpectedToRead))
let meanPercentageDone = self.calculatePercentageDoneForExhibit(exhibitId, artworkArray: self.artworkArray)
let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
appDelegate.notifyDownloadProgress(meanPercentageDone)
}
.response { _, _, _, _ in
NSLog("Completed downloading audio file,%@ , for artwork %@", musicFilename, artworkId)
if DataManager.saveMusicDownloadComplete(artworkId, exhibitId: exhibitId){
let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
appDelegate.notifyMusicDownloadsComplete(exhibitId)
self.percentageDownloaded[exhibitId] = [String: (Double, Double)?]()
NSLog("when all music files have been downloaded")
}
}
}
Как перенести выше кода Alamofire 4. Не в состоянии увидеть какие-либо комментарии в документе миграции.
Попробуйте: https://www.raywenderlich.com/121540/alamofire-tutorial-getting-started –
@JamshedAlam, учебник для Swift 2.2. К сожалению, для Swift 3 –
вы можете конвертировать его в swift 3 –