6

Is there a way to detect if any of the volume buttons on the iPhone are being held?

I know you can detect if one has been pressed, but I specifically need to know if one is being held down.

Community
  • 1
  • 1
Philip Hardy
  • 196
  • 2
  • 9

1 Answers1

2

That's not really possible, but you can have an approximation starting a timer every time you get a volume button pressed event, since you'll receive multiple events in succession when the button is hold. If every time you restart the timer, when the button is released the timer will get triggered and you can do whatever you want. 0.5 seconds worked for me.

Luca Torella
  • 7,974
  • 4
  • 38
  • 48
  • 2
    Snapchat seems to be able to distinguish hold from press without half second delay. How they do that? – Dannie P Feb 07 '16 at 17:19
  • @Luca Torella, it works but it also fires for short press, need some kind distinguishing between long and short press. On Short press the timer shouldn't fire :( – Hyder Aug 08 '16 at 08:43
  • then you should call your `longPressedVolumeButton` method only when you receive the second event. The only problem is that a double click on the volume button will be interpreted as a long click – Luca Torella Aug 08 '16 at 09:59
  • @LucaTorella I tried that, but not working as it should. Can you please provide a snippet? It will save my life! Thanks! – Hyder Aug 31 '16 at 15:10