bear-zyy

ios开发中保存照片和视频到本地相册

保存照片和视频到本地相册

1、保存视频文件到相册

1在工程中添加这个框架:

1
2
3
4
5
6
7
8
9
10
11
#import <AssetsLibrary/AssetsLibrary.h>
2、
//fileURL :为文件目录
ALAssetsLibrary * library = [[ALAssetsLibrary alloc]init];
[library writeVideoAtPathToSavedPhotosAlbum:fileURL completionBlock:^(NSURL *assetURL, NSError *error) {
if (error) {
[Uility showWindowToastWithText:@"视频保存至相册失败"];
} else {
[Uility showWindowToastWithText:@"录制完成,视频已保存至相册"];
}
}];

2、保存图片到相册

保存图片:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
UIImageWriteToSavedPhotosAlbum(image, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
// 保存图片成功或失败的回调方法:
- (void) image: (UIImage*)image didFinishSavingWithError: (NSError*) error contextInfo: (void*)contextInfo
{
//NSLog(@"save result");
if (error != nil) {
//show error message
NSLog(@"take picture failed");
}else {
//show message image successfully saved
NSLog(@"save success");
}
}
⬅️ Go back