我试图在自定义相机应用程序中设置相机的闪光灯开/关,但我尝试在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()
}
答案 0 :(得分:0)
没有粉碎日志,很难回答。
//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];
}