我观察了一些AVCaptureDevice属性的变化,其中一个是白平衡增益。我的代码是:
override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
if let newValue = change?[.newKey] as? NSValue {
if context == &DeviceWhiteBalanceGainsContext {
var gains : AVCaptureWhiteBalanceGains? = nil
newValue.getValue(&gains)
if let g = gains {
temperatureValue = Double(videoDevice.temperatureAndTintValues(forDeviceWhiteBalanceGains: g).temperature)
}
}
}
}
但它永远不会通过if let g = gains
,因为gains
是零。甚至更奇怪的是,当我在该行上设置断点时,调试窗口显示gains
不是nil且有效但在控制台po gains
中输出nil并且代码永远不会通过条件