How to download video from url and save it in to document directory in iOS
You can download it using GCD.
-(void)downloadVideoAndSave :(NSString*)videoUrl
{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSData *yourVideoData=[NSData dataWithContentsOfURL:[NSURL URLWithString:videoUrl]];
if (yourVideoData) {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath = [NSString stringWithFormat:@"%@/%@", documentsDirectory,@"video.mp4"];
if([yourVideoData writeToFile:videpPath atomically:YES])
{
NSLog(@"write successfull");
}
else{
NSLog(@"write failed");
}
}
});
}