IOS拍照自动保存到相簿

Github项目地址

================


项目来自于苹果官方文档中的一个范例。

针对这个范例,我对一些英文注释做了中文说明,并尝试着加入自动保存到相簿的这个小功能。好吧,有些过于简单了。

保存到相簿
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// 当从相册里选择一张照片或者用相机进行拍摄之后,该方法被调用
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *image = [info valueForKey:UIImagePickerControllerOriginalImage];
NSLog(@"SMILE!");
[self.capturedImages addObject:image];

if ([self.cameraTimer isValid])
{
return;
}

if (self.imagePickerController.sourceType == UIImagePickerControllerSourceTypeCamera)
{

UIImageWriteToSavedPhotosAlbum(image, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
}


[self finishAndUpdate];
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
- (void)image:(UIImage*)image didFinishSavingWithError:(NSError*)error contextInfo:(void*)contextInfo
{
UIAlertView *alert;

if (error)
{
alert = [[UIAlertView alloc] initWithTitle:@"错误"
message:@"保存失败"
delegate:self cancelButtonTitle:@"确定"
otherButtonTitles:nil];
}
else
{
alert = [[UIAlertView alloc] initWithTitle:@"成功"
message:@"保存成功"
delegate:self cancelButtonTitle:@"确定"
otherButtonTitles:nil];
}
[alert show];
}

后面要加入的功能

  • 将拍照的照片存储到应用沙盒中
坚持原创技术分享,您的支持将鼓励我继续创作!