【问题标题】:Front Camera Crash when turning flash for custom camera?为自定义相机转动闪光灯时前置相机崩溃?
【发布时间】:2018-09-18 11:32:58
【问题描述】:

我尝试在自定义相机应用程序中为相机设置闪光灯开/关,我正在尝试设置,但相机在 iPhone 6 的前置摄像头模式下打开闪光灯时不断崩溃。感谢任何帮助。谢谢。

if ((currentCamera?.hasFlash)!) {
    do {
        _ = try currentCamera?.lockForConfiguration()
    } catch {
        print("aaaa")
    }

    if (currentCamera?.isTorchActive)! {
        sender.setImage(UIImage(named: "flashOff"), for: .normal)
        currentCamera?.torchMode = AVCaptureDevice.TorchMode.off
    } else {
        // sets the torch intensity to 100%
        do {
            sender.setImage(UIImage(named: "flash"), for: .normal)
            _ = try currentCamera?.setTorchModeOn(level: 1.0)
        } catch {
            print("bbb")
        }
        //    avDevice.setTorchModeOnWithLevel(1.0, error: nil)
    }
    // unlock your device
    currentCamera?.unlockForConfiguration()
}

【问题讨论】:

    标签: ios avfoundation swift4 avcapturedevice


    【解决方案1】:

    没有粉碎日志很难回答。

    //this code works for me. 
    
    if ([self.captureDevice isFlashAvailable]) {
        if (self.captureDevice.flashActive) {
            if([self.captureDevice lockForConfiguration:nil]) {
                self.captureDevice.flashMode = AVCaptureFlashModeOff;
                [sender setTintColor:[UIColor grayColor]];
                [sender setSelected:NO];
            }
        }
        else {
            if([self.captureDevice lockForConfiguration:nil]) {
                self.captureDevice.flashMode = AVCaptureFlashModeOn;
                [sender setTintColor:[UIColor blueColor]];
                [sender setSelected:YES];
            }
        }
        [self.captureDevice unlockForConfiguration];
    }
    

    【讨论】:

    • 崩溃发生时发生了什么。我的意思是,有任何理由显示吗?或者您能否逐行调试,以便您找出发生崩溃的行。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-06-11
    • 2011-10-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多