美文网首页
swfit5 打开手电筒

swfit5 打开手电筒

作者: 丹学徒 | 来源:发表于2021-12-02 14:43 被阅读0次
     @objc func toggleTorch(on: Bool) {
            guard let device = AVCaptureDevice.default(for: AVMediaType.video) else { return }
            guard device.hasTorch else { print("Torch isn't available"); return }
    
            do {
                try device.lockForConfiguration()
                device.torchMode = on ? .on : .off
                // Optional thing you may want when the torch it's on, is to manipulate the level of the torch
                if on { try device.setTorchModeOn(level: AVCaptureDevice.maxAvailableTorchLevel) }
                device.unlockForConfiguration()
            } catch {
                print("Torch can't be used")
            }
        }
    

    相关文章

      网友评论

          本文标题:swfit5 打开手电筒

          本文链接:https://www.haomeiwen.com/subject/paiyxrtx.html