I have used
NotificationCenter.default.addObserver(self, selector: #selector(volumeChanged(_:)), name: NSNotification.Name(rawValue: "AVSystemController_SystemVolumeDidChangeNotification"), object: nil)
in the past to listen to volume control changes however this no longer works in iOS 15.
This alternative code below only works well if you don't care about a user pressing the volume up when at max volume. However, I do want to know every time the button is pressed.
AVAudioSession.sharedInstance().addObserver(self, forKeyPath: "outputVolume", options: NSKeyValueObservingOptions.new, context: nil)
What is the correct way to listen to the user pressing the volume control button even when the volume is at its max/min?