问题
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