我想检测何时按下音量按钮。我尝试了很多东西,比如添加一个 Observer,比如
AVAudioSession.sharedInstance().addObserver(self, forKeyPath: #keyPath(AVAudioSession.outputVolume), options: [.old, .new], context: nil)
然后覆盖:
override internal func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey: Any]?, context: UnsafeMutableRawPointer?)
但我想即使声音最大也能触发这个功能。
有一种方法可以在不改变声音的情况下做到这一点吗?
最佳答案
尝试
AVAudioSession.sharedInstance().setActive(true)
AVAudioSession.sharedInstance().observe(\.outputVolume) { [weak self] (audioSession, _) in
<#code#>
}
关于ios - 检测音量按钮即使在音量最大时按下,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53746799/