iOS torchActive总是返回false

时间:2015-11-23 11:50:58

标签: ios torch

我想测试火炬,所以我写了一些代码

    guard let camera = camera else {
        return
    }
    if camera.hasTorch {
        do {
            try camera.lockForConfiguration()
            if camera.torchActive {
                if camera.isTorchModeSupported(.Off) {
                    camera.torchMode = .Off
                }
            } else {
                if camera.isTorchModeSupported(.On) {
                    camera.torchMode = .On
                }
            }
            camera.unlockForConfiguration()
        } catch {

        }

}

camera = AVCaptureDevice.defaultDeviceWithMediaType(AVMediaTypeVideo)是一个成员变量。像这样private var camera: AVCaptureDevice?

问题是我只能制作火炬模型= .On,因为火炬活动总会返回闪光灯!

0 个答案:

没有答案