如何用ARKit打开/ offf相机闪光灯?

Har*_*nda 2 ios swift arkit

我正在使用一个ARSCNView用于显示AR体验,用3D SceneKit内容增强相机视图.

ARSession共享管理设备摄像头的对象,但在ARSession 我找不到闪光灯的任何选项.

有没有办法打开/关闭相机闪光灯?

如何管理相机ARKit

如何正面和背面改变相机位置?

小智 8

func toggleTorch(on: Bool) {
        guard let device = AVCaptureDevice.default(for: AVMediaType.video) 
        else {return}

        if device.hasTorch {
            do {
                try device.lockForConfiguration()

                if on == true {
                    device.torchMode = .on // set on
                } else {
                    device.torchMode = .off // set off
                }

                device.unlockForConfiguration()
            } catch {
                print("Torch could not be used")
            }
        } else {
            print("Torch is not available")
        }
    }
Run Code Online (Sandbox Code Playgroud)

称之为

toggleTorch(on:false)的toggleTorch(on:true)

ref:用Swift攻击