Вы можете сохранить файл mp4 в рулон камеры, если она использует supported codecs. Например:
NSURL *sourceURL = [NSURL URLWithString:@"http://path/to/video.mp4"];
NSURLSessionTask *download = [[NSURLSession sharedSession] downloadTaskWithURL:sourceURL completionHandler:^(NSURL *location, NSURLResponse *response, NSError *error) {
NSURL *documentsURL = [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] firstObject];
NSURL *tempURL = [documentsURL URLByAppendingPathComponent:[sourceURL lastPathComponent]];
[[NSFileManager defaultManager] moveItemAtURL:location toURL:tempURL error:nil];
UISaveVideoAtPathToSavedPhotosAlbum(tempURL.path, nil, NULL, NULL);
}];
[download resume];
Или, на IOS 6 и выше:
NSURL *sourceURL = [NSURL URLWithString:@"http://path/to/video.mp4"];
NSURLRequest *request = [NSURLRequest requestWithURL:sourceURL];
[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
NSURL *documentsURL = [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] firstObject];
NSURL *tempURL = [documentsURL URLByAppendingPathComponent:[sourceURL lastPathComponent]];
[data writeToURL:tempURL atomically:YES];
UISaveVideoAtPathToSavedPhotosAlbum(tempURL.path, nil, NULL, NULL);
}];
Большого спасибо за ваш вклад, ваше решение, кажется, прекрасно работает в прошивке 7, но мне нужно, чтобы заставить его работать в iOS 6.1+. Есть идеи? – SeanT
Вам необходимо загрузить файл с помощью 'NSURLConnection' или сторонней библиотеки. Вы все равно захотите записать его в временном файле, а затем вызвать 'UISaveVideoAtPathToSavedPhotosAlbum'. – jonahb
@SeanT, я добавил пример iOS 6. – jonahb