When the iPhone is silent then after pressing the volume up button the phone goes to ringer state. How to catch this volume button pressed? Is there any method to catch the button pressed while any media is playing. I have tried code and it is working hen the physical silent key is operating i.e. when I am using the physical mute switch to silent the phone then the media player sound turning off and then again I am making it to ringer using the switch then the sound is again turned on. But when it is on silent pressing the volume up button then the iPhone is going into ringer mode but the media player sound is still off.
I am using AVAudioPlayer to play the media. I have tried using this but it is not working except the above scenario. I have also used AVSystemController_SystemVolumeDidChangeNotification but it is not also working as the method is deprecated and Apple does not give any access to control or getting any notification on when the hardware button is pressed.
do {
try AVAudioSession.sharedInstance().setCategory(AVAudioSession.Category.soloAmbient)
} catch {
print("AVAudioSessionCategorySoloAmbient not work")
}