Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS 7 AVCaptureTorchModeAuto doesn't seem to activate torch in low light

I've set an AVCaptureDevice TorchMode to AVCaptureTorchModeAuto, the torch mode is set after the AVCaptureSession has started running. I'd expected the torch mode to light-up the LED in low light conditions as per Apple's documentation: https://developer.apple.com/library/ios/documentation/AVFoundation/Reference/AVCaptureDevice_Class/Reference/Reference.html#//apple_ref/doc/c_ref/AVCaptureTorchMode

However, the torch does not turn on in any light conditions on my test devices: iPhone 4S, iPhone 5. Has anyone had this issue?

Here's my code:

- (void)enableTorchMode
{
    if ((self.device.hasTorch) && ([self.device isTorchModeSupported:AVCaptureTorchModeAuto]))
    {
        [self.device lockForConfiguration:nil];
        self.device.torchMode = AVCaptureTorchModeAuto;
        [self.device unlockForConfiguration];
    }
}
like image 598
user3183222 Avatar asked Jan 10 '14 19:01

user3183222


1 Answers

You don't mention what you're doing with the camera, but currently (as of iOS 7.1), the auto torch mode doesn't work unless the AVCaptureSession has a video output. This made sense when the only other options were photos or audio, but if you're only interested in metadata like faces or barcodes, then it's a problem.

You can use something like this when you're setting up the session to force it to work:

if ([captureDevice isTorchModeSupported:AVCaptureTorchModeAuto]) {
    AVCaptureOutput *videoOutput = [[AVCaptureVideoDataOutput alloc] init];
    [session addOutput:videoOutput];
}

If this is the problem you're having, I'd recommend filing a bug report. Feel free to dupe mine.

like image 122
robotspacer Avatar answered Oct 06 '22 02:10

robotspacer