How to observe torchLevel in swift?

本秂侑毒 提交于 2019-12-08 03:23:53

问题


How do I observe torchLevel? I have done the following from objective c solutions, no success:

private var torchLevel = 0

let device = AVCaptureDevice.defaultDeviceWithMediaType(AVMediaTypeVideo)
    device.addObserver(self, forKeyPath: "torchLevel", options: .New, context: &torchLevel)

override func observeValueForKeyPath(keyPath: String?, ofObject object: AnyObject?, change: [String : AnyObject]?, context: UnsafeMutablePointer<Void>) {
    if context == &torchLevel {
        let device = object as! AVCaptureDevice
        print("level \(device.torchLevel)")
    } else {
        print("Nope")
    }
}

my alternate direction would be to turn torch off and set a variable to 0.0 and update that as the flash is manipulated.

来源:https://stackoverflow.com/questions/40033800/how-to-observe-torchlevel-in-swift

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!