AVCaptureDevice isTorchActive总是返回NO

时间:2015-01-30 13:58:59

标签: ios objective-c iphone avcapturedevice

以下代码无法正常运行:

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]即使处于有效状态也会返回NO。

UPD:用if(flashLight.torchMode == AVCaptureTorchModeOn)替换([flashLigh isTorchActive])有帮助。但是如果火炬先前已从控制中心激活,那么我第一次运行此代码时会得到AVCaptureTorchModeOff。

0 个答案:

没有答案