【发布时间】:2018-12-07 19:21:11
【问题描述】:
如何在 ARSession 期间打开手电筒(手电筒)?
标准代码不起作用,只要会话开始,手电筒就关闭了。
初始化 ARSession:
let configuration = ARWorldTrackingConfiguration()
self.sceneView.session.run(configuration, options: [.removeExistingAnchors])
打开/关闭手电筒的功能:
private func turnTorch(enabled: Bool) {
guard let device = AVCaptureDevice.default(for: AVMediaType.video) else {
return // Cant initiate avcapturedevice error
}
if device.hasTorch {
do {
try device.lockForConfiguration()
if enabled {
device.torchMode = .on
} else {
device.torchMode = .off
}
device.unlockForConfiguration()
} catch {
return //Torch could not be used, lock for configuration failed
}
} else {
return // Torch not available error
}
}
【问题讨论】:
标签: ios swift arkit flashlight