4

I downloaded the AVCam demo from the apple site and tried to add a simple start screen (I added a StartViewController.{h,m,nib}) with a button that would then launch the AVCam demo. The code for the button is as follows (everything else is just the default stuff created by xcode):

-(IBAction) btnClicked:(id) sender {
    viewController =
    [[AVCamViewController alloc]
        initWithNibName: @"AVCamViewController"
        bundle:nil];

    [UIView beginAnimations:@"flipping view" context:nil];
    [UIView setAnimationDuration:1];
    [UIView setAnimationTransition:UIViewAnimationTransitionCurlUp
                       forView:self.view
                         cache:YES];
    [self.view addSubview:viewController.view];
    [UIView commitAnimations];
}

Somehow after adding this nib, taking a photo does not work all the time (sometimes no picture ends up in the camera roll). I added some log statements to captureStillImage in the captureStillImageAsynchronouslyFromConnection:stillImageConnection completionHandler and noticed that this completionHandler does not always get called. Weird thing is that it does work some of the time. My guess is that I'm doing something wrong but not sure what? I'm testing this on an iPhone running 4.2.1.

michael
  • 41
  • 2

3 Answers3

2

Make sure that the AVCaptureSession is running when calling captureStillImageAsynchronouslyFromConnection:stillImageConnection

Or Arbel
  • 2,965
  • 2
  • 30
  • 40
  • It is definitely running. I have the following check: if (![session isRunning]) NSLog(@"sesion isn't running!?!", nil); The AVCam code is basically untouched. The only thing that changed was adding the start view. – michael Jan 05 '12 at 08:51
1

Well, i was facing a similar issue where by the captureStillImageAsynchronouslyFromConnection:stillImageConnection was raising an exception that the passed connection is invalid. Later on, i figured out that when i made properties for the session and stillImageOutPut to retain values, the issue got resolved.

Jamal Zafar
  • 2,179
  • 2
  • 27
  • 32
0

For me, this issue ONLY happened on single core iPhone 4 and when I try to capture still image with AVCaptureSessionPresetHigh.

I tried AVCaptureSessionPresetPhoto and this issue disappeared. But I don't need full size photo so I went for another solution.

I put captureStillImageAsynchronouslyFromConnection in the main queue. Something like this

dispatch_async(sessionQueue) {

    // do whatever before capturing

    dispatch_async(dispatch_get_main_queue) {
        captureStillImageAsynchronouslyFromConnection {
            // do whatever after capturing
        }
    }
}

Not sure why this issue exists and not sure why this can avoid it. But I hope this can help someone.

ethanchli
  • 296
  • 4
  • 8