You would do something like this:
- (void) downloadVideo
NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://www.xyz.com/image.mp4"]];
NSString *tempPath = [NSString stringWithFormat:@"%@/%@", NSTemporaryDirectory(), temp.mp4];
[imageData writeToFile:tempPath atomically:NO];
UISaveVideoAtPathToSavedPhotosAlbum (@ tempPath, self, @selector(video:didFinishSavingWithError: contextInfo:), nil);
);
- (void) video: (NSString *) videoPath
didFinishSavingWithError: (NSError *) error
contextInfo: (void *) contextInfo {
NSLog(@"Finished saving video with error: %@", error);
}
There are two things you need to take note of:
- Make sure you specify the scheme of the URL. This isn't a browser, it is not going to attempt to autofill http and guess for you.
- If this is on the main thread it will cause a synchronous stall while
dataWithContentsOfURL:
happens. If the main thread stalls for more than 20 seconds the phone will assume the app has gotten stuck in an infinite loop and kill it. So if this code is on the main thread you need to either move it onto a background thread or move to an asynchronous download using NSURLConnection.