CaptureStillImageAsynchronouslyFromConnection: stillImageConnection completeHandler does not always receive a call

I downloaded the AVCam demo from the apple website and tried to add a simple start-up screen (I added the StartViewController. {H, m, nib}) with a button that then starts the AVCam demo. The code for the button is as follows (everything else is just the default material 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 tip, photography does not work all the time (sometimes there is no image in the camera frame). I added several log statements to captureStillImage in captureStillImageAsynchronouslyFromConnection: stillImageConnection completeHandler and noticed that this completion method is not always called. It is strange that it works for a while. I suppose I'm doing something wrong, but not sure what? I am testing this on an iPhone with 4.2.1.

+4
source share
3 answers

Verify that AVCaptureSession works when calling captureStillImageAsynchronouslyFromConnection:stillImageConnection

+2
source

Well, I ran into a similar problem when captureStillImageAsynchronouslyFromConnection:stillImageConnection exception that the connection passed invalid. Later I realized that when I made properties for the session and stillImageOutPut to save the values, the problem was resolved.

+1
source

For me, this problem ONLY happened on the same iPhone 4 core, and when I try to capture a still image using AVCaptureSessionPresetHigh.

I tried AVCaptureSessionPresetPhoto and this question disappeared. But I do not need a full-sized photograph, so I went for another solution.

I put captureStillImageAsynchronouslyFromConnection in the main queue. Something like that

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

I don’t know why this problem exists, and I’m not sure why it can avoid it. But I hope this can help someone.

0
source

Source: https://habr.com/ru/post/1389412/


All Articles