2

I have used AVCaptureSession for capture photo in iPhone application. As well as I want to take an image from PhotosLibrary too.

I've implemented UIImagePickerController control and its all methods.

I can open library, But I can't get photo which I've selected. As well as not calling PickerView's methods. No response from those methods.

Is there any different way to implement UIImagePickerController control with AVCaptureSession for photos library?

Please tell me solution.

Or suggest me alternative solution instead of Overlay as I want both functionality with dynamic controls.

Thanks in advance.

Sven Hohenstein
  • 80,497
  • 17
  • 145
  • 168
Manann Sseth
  • 2,745
  • 2
  • 30
  • 50

1 Answers1

2

For open photo library use this:

-(IBAction)pickphoto:(id)sender
{
    [self startMediaBrowserFromViewController: self usingDelegate: self];
}

- (BOOL) startMediaBrowserFromViewController: (UIViewController*) controller
                               usingDelegate: (id <UIImagePickerControllerDelegate,
                                               UINavigationControllerDelegate>) delegate{

    if (([UIImagePickerController isSourceTypeAvailable:
          UIImagePickerControllerSourceTypeSavedPhotosAlbum] == NO)
        || (delegate == nil)
        || (controller == nil))
        return NO;

    UIImagePickerController *mediaUI = [[UIImagePickerController alloc] init];
    mediaUI.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;

    mediaUI.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *) kUTTypeMovie,kUTTypeImage, nil];
    mediaUI.allowsEditing = YES;

    mediaUI.delegate = delegate;

    [controller presentModalViewController: mediaUI animated: YES];
    return YES;

}

- (void) imagePickerController: (UIImagePickerController *) picker
 didFinishPickingMediaWithInfo: (NSDictionary *) info
{

    NSString *mediaType = [info objectForKey: UIImagePickerControllerMediaType];
 thumbnail = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
 [self dismissModalViewControllerAnimated:YES];
}

And for capture a Image use this:

UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];

imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;

imagePicker.delegate = self;

[self presentViewController:imagePicker animated:YES completion:nil];
Vishal
  • 8,246
  • 6
  • 37
  • 52
  • In .h also declare UINavigationControllerDelegate & also mention this in .h file:- (BOOL) startMediaBrowserFromViewController: (UIViewController*) controller usingDelegate: (id ) delegate; – Vishal Dec 12 '12 at 07:21
  • I've tried with same UIImagePickerController but is there any difference in "- (BOOL) startMediaBrowserFromViewController: (UIViewController*) controller usingDelegate: (id )" method ?? – Manann Sseth Dec 12 '12 at 09:11
  • 1
    I think perhaps. some day ago I am also stuck at this point then I am searching this method and implement it and it is working fine. I am also try like you. – Vishal Dec 12 '12 at 09:14