I\'m downloading a video thanks to downloadTaskWithURL and I\'m saving it to my gallery with this code :
func saveVideoBis(fileStringURL:String){
pr
If you want to download Video from URL but don't want to store it on Gallery. following code works for me...
func createDownloadTask(videoURL: String,index: Int) {
let downloadRequest = NSMutableURLRequest(url: URL(string: videoURL)!)
let session = URLSession(configuration: URLSessionConfiguration.default, delegate: self, delegateQueue: OperationQueue.main)
self.downloadTask = session.downloadTask(with: downloadRequest as URLRequest, completionHandler: { (url, response, error) in
print("asdasd")
if error != nil{
if super.reachability.connection == .none{
self.showalert(msg: error?.localizedDescription ?? "")
}else{
self.downloadTask?.resume()
}
}
guard let documentsDirectoryURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first else { return }
// create a deatination url with the server response suggested file name
let destinationURL = documentsDirectoryURL.appendingPathComponent(response?.suggestedFilename ?? "")
do {
if url != nil{
try FileManager.default.moveItem(at: url!, to: destinationURL)
}
}
} catch { print(error) }
})
self.downloadTask!.resume()
}