Detect iOS volume changes from specific audio source

60 views Asked by At

In an iOS app I need to detect the user pressing the volume down button on a certain screen and to do an action when it occurs.

To do this I use JPSVolumeButtonHandler which works by detecting system volume changes and triggering an action on the volume being decreased. This works fine, mostly.

The problem is when the iOS device is connected to Bluetooth, like a car audio, the Bluetooth source sometimes just changes the volume without users interaction triggering the action.

I can simulate the problem even without a car audio just by connecting Bluetooth headphones and changing volume on those headphones, which undesirably triggers the actions.

I looked at AVAudioSession.currentRoute and outputs and with this I can detect a Bluetooth device being connected but that is not enough, I cannot just disable the functionality when I see an Bluetooth output device because the action should be still triggered when the user for example uses Bluetooth headphones and presses the volume down button on the device.

I need to find some way to react to volume changes (as there is no better way to detect volume down button being pressed) but only when triggered by the device volume buttons, not via Bluetooth.

0

There are 0 answers