How to download video from url and save it in to document directory in iOS
You can also implement same in Swift 2.0
class func downloadVideo(videoImageUrl:String)
{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), {
//All stuff here
let url=NSURL(string: videoImageUrl)
let urlData=NSData(contentsOfURL: url!)
if((urlData) != nil)
{
let documentsPath = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0]
let fileName = videoImageUrl.lastPathComponent //.stringByDeletingPathExtension
let filePath="\(documentsPath)/\(fileName)"
//saving is done on main thread
dispatch_async(dispatch_get_main_queue(), { () -> Void in
urlData?.writeToFile(filePath, atomically: true)
})
}
})
}