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];
}
}
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With