简体   繁体   English

UIImagePickerController相机不保存照片库中的照片

[英]UIImagePickerController Camera Not saving Photos in Photo Library

Has anyone ever had this problem before? 以前有没有人遇到这个问题? I'm using the UIImagePickerController Camera to take photos with my application, and I noticed the photos are not being stored in the photo library after being taken. 我正在使用UIImagePickerController相机拍摄我的应用程序的照片,我发现照片在拍摄后没有存储在照片库中。 I've tried it both on iOS5 with the iPhone4 and iOS6 with the iPhone5 and same result. 我已经在iOS5上使用iPhone4和iOS6以及iPhone5进行了尝试,结果相同。 Here is how I'm setting it up: 这是我如何设置它:

UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
    imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
}

imagePickerController.delegate = self;
[self.navigationController presentModalViewController:imagePickerController animated:YES];
[imagePickerController release];

Seems as though the UIImagePickerController should implicitly save a photo that's taken to the users photo library? 似乎UIImagePickerController应隐式保存拍摄到用户照片库的照片? Any help would be appreciated thanks. 任何帮助将不胜感激。

Try following code. 请尝试以下代码。

-(IBAction)useCamera
{
 if ([UIImagePickerController isSourceTypeAvailable:
      UIImagePickerControllerSourceTypeCamera])
 {
  UIImagePickerController *imagePicker =
  [[UIImagePickerController alloc] init];
  imagePicker.delegate = self;
  imagePicker.sourceType =
  UIImagePickerControllerSourceTypeCamera;
  imagePicker.mediaTypes = [NSArray arrayWithObjects:
                            (NSString *) kUTTypeImage,
                            nil];
  imagePicker.allowsEditing = NO;
  [self presentViewController:imagePicker animated:YES completion:nil];
  newMedia = YES;
 }
}

#pragma mark- camera picker delegate methods

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
 NSString *mediaType = [info
                        objectForKey:UIImagePickerControllerMediaType];

 [self dismissViewControllerAnimated:YES completion:nil];

 if ([mediaType isEqualToString:(NSString *)kUTTypeImage]) {
  UIImage *image = [info
                    objectForKey:UIImagePickerControllerOriginalImage];

  [imageView setAutoresizingMask:(UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth)];
  imageView.image = image;
  if (newMedia)
   UIImageWriteToSavedPhotosAlbum(image,
                                  self,
                                  @selector(image:finishedSavingWithError:contextInfo:),
                                  nil);
 }
 else if ([mediaType isEqualToString:(NSString *)kUTTypeMovie])
 {
  // Code here to support video if enabled
 }
}

-(void)image:(UIImage *)image
finishedSavingWithError:(NSError *)error
 contextInfo:(void *)contextInfo
{
 if (error) {
  UIAlertView *alert = [[UIAlertView alloc]
                        initWithTitle: @"Save failed"
                        message: @"Failed to save image"\
                        delegate: nil
                        cancelButtonTitle:@"OK"
                        otherButtonTitles:nil];
  [alert show];
 }
}

Pick photo from camera and store it to ImageView and call save method to save it to camera roll. 从相机中选取照片并将其存储到ImageView并调用保存方法将其保存到相机胶卷。 May this will help 愿这会有所帮助

Have you implemented the methods of UIImagePickerControllerDelegate methods? 你有没有实现UIImagePickerControllerDelegate方法的方法?

The most important method is the didFinishPickingMediaWithInfo which is called when the user has finished taking or selecting an image. 最重要的方法是didFinishPickingMediaWithInfo ,它在用户完成拍摄或选择图像时调用。

link : http://www.techotopia.com/index.php/An_Example_iOS_4_iPad_Camera_and_UIImagePickerController_Application_%28Xcode_4%29 链接: http//www.techotopia.com/index.php/An_Example_iOS_4_iPad_Camera_and_UIImagePickerController_Application_%28Xcode_4%29

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM