我想测试火炬,所以我写了一些代码
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,因为火炬活动总会返回闪光灯!