Kapil Choubisa
Kapil Choubisa

Reputation: 5232

UIImagePickerController takePicture is not calling any delegate method

I am creating a sample app which allow use to capture image and record video with custom buttons. I created an instance of UIImagePicker controller and assign delegate and all is done but takePicture, is not calling delegate method.

I refer few of post too UIImagePickerController takePicture not responding and UIImagepickerController [takepicture] modal view disappears no delegate callback but not getting my solution.

Here is my code. Please let me know if I am missing anything:

- (void)viewDidLoad {
[super viewDidLoad];

self.navigationController.navigationBar.hidden = YES;
imagePicker = [[UIImagePickerController alloc] init];
[imagePicker setSourceType:UIImagePickerControllerSourceTypeCamera];
[imagePicker setAllowsEditing:NO];

[imagePicker setMediaTypes:[NSArray arrayWithObject:@"public.movie"]];
[imagePicker setCameraCaptureMode:UIImagePickerControllerCameraCaptureModeVideo];

[imagePicker setShowsCameraControls:NO];
[imagePicker setToolbarHidden:YES];
[imagePicker setDelegate:self];
UIView *overlayView = [[UIView alloc] initWithFrame:[[imagePicker view]frame]];
[overlayView setBackgroundColor:[UIColor clearColor]];

UIButton *btnCapture = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[btnCapture setFrame:CGRectMake(0, overlayView.frame.origin.y + overlayView.frame.size.height - 35, 30, 30)];
[btnCapture setTitle:@"c" forState:UIControlStateNormal];
[btnCapture addTarget:self action:@selector(captureFrame:) forControlEvents:UIControlEventTouchUpInside];

UIButton *btnStopVideo = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[btnStopVideo setFrame:CGRectMake(40, overlayView.frame.origin.y + overlayView.frame.size.height - 35, 30, 30)];
[btnStopVideo setTitle:@"s" forState:UIControlStateNormal];
[btnStopVideo addTarget:self action:@selector(btnStopTapped:) forControlEvents:UIControlEventTouchUpInside];

[overlayView addSubview:btnStopVideo];
[overlayView addSubview:btnCapture];
[imagePicker setCameraOverlayView:overlayView];

[self presentModalViewController:imagePicker animated:NO];



}

- (void)captureFrame:(id)sender {
[imagePicker takePicture];
}  

But delegate method:- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info is not being called.

Please help me to solve this issue.

Thanks to all

Upvotes: 2

Views: 2250

Answers (3)

nullLululi
nullLululi

Reputation: 194

You better to check if your UIImagePickerController.delegate still your controller.

Upvotes: 0

WrightsCS
WrightsCS

Reputation: 50697

You need to make sure you implement the UIImagePickerControllerDelegate protocol in your header.

.h

@interface MyViewController <UIImagePickerControllerDelegate>
{
    // 
}

@end

Upvotes: 0

smear_jd
smear_jd

Reputation: 31

Just add this line

    picker.showsCameraControls = NO;

Upvotes: 3

Related Questions