iOS 保存视频到相册

1.

1
#import <AssetsLibrary/AssetsLibrary.h>

2.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
-(void) saveVideoToCameraRoll{
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
[library writeVideoAtPathToSavedPhotosAlbum:self.outputPath completionBlock:^(NSURL *assetURL, NSError *error){
NSLog(@"ASSET URL: %@", [assetURL path]);
if(error) {
NSLog(@"CameraViewController: Error on saving movie : %@ {imagePickerController}", error);
}
else {
NSLog(@"Video salvato correttamente in URL: %@", assetURL);
BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:[self.outputPath path]];
NSLog(@"IL FILE ESISTE: %hhd", fileExists);
NSLog(@"E PESA: %@", [[[NSFileManager defaultManager] attributesOfItemAtPath: [self.outputPath path] error:&error] objectForKey:NSFileSize]);
dispatch_async(dispatch_get_main_queue(), ^{
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"友情提示" message:@"视频已保存到相册" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil];
[alert show];
});
}
}];
}