Following code doesn't work correctly:
AVCaptureDevice *flashLight = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
if ([flashLight isTorchAvailable] && [flashLight isTorchModeSupported:AVCaptureTorchModeOn])
{
BOOL success = [flashLight lockForConfiguration:nil];
if (success)
{
if ([flashLight isTorchActive])
{
//TURN OFF
[flashLight setTorchMode:AVCaptureTorchModeOff];
}
else
{
//TURN ON
[flashLight setTorchMode:AVCaptureTorchModeOn];
}
[flashLight unlockForConfiguration];
}
}
[flashLight isTorchActive]
returns NO even if it's active.
UPD: Replacing ([flashLigh isTorchActive]) with if (flashLight.torchMode == AVCaptureTorchModeOn) helped. But if torch was previously activated from Control Center, i get AVCaptureTorchModeOff, when running this code first time.
Aucun commentaire:
Enregistrer un commentaire