If you can use the AFNetworking library, it's pretty simple. You can make an HTTP request and use the outputStream property to download the file to your device. Let's say you connect the download button to the downloadVideoFromURL:withName:
- (void)downloadVideoFromURL:(NSURL*)url withName:(NSString*)videoName { //filepath to your app documents directory NSString *appDocPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]; NSString *videosPath = [appDocPath stringByAppendingPathComponent:@"Videos"]; NSString *filePath = [videosPath stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.mp4", videoName]]; //check to make sure video hasn't been downloaded already if ([[NSFileManager defaultManager] fileExistsAtPath:filePath]) { //file was already downloaded } //video wasn't downloaded, so continue else { //enable the network activity indicator [AFNetworkActivityIndicatorManager sharedManager].enabled = YES; NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url]; AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:urlRequest]; //create a temporary filepath while downloading NSString *tmpPath = [videosPath stringByAppendingPathComponent:[NSString stringWithFormat:@"%@-tmp.mp4", videoName]]; //the outputStream property is the key to downloading the file operation.outputStream = [NSOutputStream outputStreamToFileAtPath:tmpPath append:NO]; //if operation is completed successfully, do following [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) { //rename the downloaded video to its proper name [[NSFileManager defaultManager] moveItemAtPath:tmpPath toPath:filePath error:nil]; //disable network activity indicator [AFNetworkActivityIndicatorManager sharedManager].enabled = NO; //optionally, post a notification to anyone listening that the download was successful [[NSNotificationCenter defaultCenter] postNotificationName:@"DownloadedVideo" object:nil]; //if the operation fails, do the following: } failure:^(AFHTTPRequestOperation *operation, NSError *error) { NSLog(@"error: %@", error); //delete the downloaded file (it is probably partially downloaded or corrupt) [[NSFileManager defaultManager] removeItemAtPath:tmpPath error:nil]; //disable network activity indicator [AFNetworkActivityIndicatorManager sharedManager].enabled = NO; }]; //start the operation [operation start]; } }
source share