尽管设置了AVCapture TorchModeOff,IOS 8火炬在黑暗时也会亮起

时间:2014-10-10 11:14:59

标签: ios objective-c iphone ios8

使用下面的代码禁用火炬在ios7中正常工作, 但是在ios8火炬在黑暗中开启

 AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
                    if ([device hasTorch] || [device hasFlash]){
                        [device lockForConfiguration:nil];
                        [device setTorchMode:AVCaptureTorchModeOff];
                        [device setFlashMode:AVCaptureFlashModeOff];
                        [device unlockForConfiguration];
                    }

1 个答案:

答案 0 :(得分:2)

试试这个有效的代码......

 - (IBAction)flashOnClicked:(id)sender
    {
        AVCaptureDevice *flashLight = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
        if ([flashLight isTorchAvailable] && [flashLight isTorchModeSupported:AVCaptureTorchModeOn])
        {
            BOOL success = [flashLight lockForConfiguration:nil];
            if (success)
            {
                if ([flashLight isTorchActive])
                {
                    //TURN ON
                    [flashLight setTorchMode:AVCaptureTorchModeOff];
                }
                else
                {
                    //TURN OFF
                    [flashLight setTorchMode:AVCaptureTorchModeOn];
                }
                [flashLight unlockForConfiguration];
            }
        }
    }