0
下載使用SessionManager一個音頻文件Alamofire 4在alomofire 3.5下面的代碼行之有效斯威夫特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,該教程是斯威夫特2.2。可惜不是Swift 3 –
你可以把它轉換成swift 3 –