Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
- if indexPath.row > 0 {
- let path = NSSearchPathForDirectoriesInDomains(FileManager.SearchPathDirectory.documentDirectory, FileManager.SearchPathDomainMask.userDomainMask, true)
- print(path)
- let documentDirectoryPath:String = path[0]
- let fileManager = FileManager()
- let destinationURLForFile = URL(fileURLWithPath: documentDirectoryPath.appendingFormat("/file(indexPath.row).mp3"))
- if fileManager.fileExists(atPath: destinationURLForFile.path){
- self.performSegue(withIdentifier: "segue", sender: self)
- }else{
- index = indexPath.row
- let url = URL(string: "http:link(indexPath.row).mp3")!
- let downloadTaskLocal = backgroundSession.downloadTask(with: url)
- downloadTaskLocal.resume()
- }
- }
- }
- func urlSession(_ session: URLSession,
- downloadTask: URLSessionDownloadTask,
- didFinishDownloadingTo location: URL){
- let path = NSSearchPathForDirectoriesInDomains(FileManager.SearchPathDirectory.documentDirectory, FileManager.SearchPathDomainMask.userDomainMask, true)
- let documentDirectoryPath:String = path[0]
- let fileManager = FileManager()
- let destinationURLForFile = URL(fileURLWithPath: documentDirectoryPath.appendingFormat("/file(index).mp3"))
- do {
- try fileManager.moveItem(at: location, to: destinationURLForFile)
- }catch{
- print("error")
- }
- }
- fileManager.moveItem(at: location, to: destinationURLForFile)
- let fileName = location.lastPathComponent
- let destinationURLForFile = URL(fileURLWithPath: documentDirectoryPath.appendingFormat("/(fileName)"))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement