2

I would like to detect the silent button's position (the button that switches the volume on or off). I'm making an app that plays a sound in the background, but I would like to detect if the ringer is activated so I won't play the sound. After all, if the user put his phone's volume at off, he doesn't want my app to play loud sounds.

By the way, I need to know the button's position for all iOS devices, not only iPhone.

Thanks in advance.

anthoprotic
  • 827
  • 2
  • 13
  • 24
  • 2
    If the phone's volume is off, your app won't be able to play a sound anyway so I'm not sure why it matters. – Ethan Holshouser Jul 25 '12 at 18:29
  • The volume is not necessary off when the switch is activated. If you have ever played some games on an iPhone, you know that usually it's possible to turn off the volume of the game by activating that switch. My goal is to detect the position of that switch. – anthoprotic Jul 25 '12 at 18:39
  • Yes, but your stated reason is that you want to avoid playing a sound if the phone's volume is off... – Ethan Holshouser Jul 25 '12 at 18:46
  • Sorry, I should have said "if the user activates his phone's mute button", then I don't want to play sounds. – anthoprotic Jul 25 '12 at 19:42

4 Answers4

1

Please take a look at this answer.

If you are making an app for jailbroken devices, you might want to take a look at UIHardware.

Community
  • 1
  • 1
David Murray
  • 541
  • 5
  • 19
1

I suggest you check out RDBMuteSwitch.

Jason
  • 14,517
  • 25
  • 92
  • 153
1

If you just want to make your sound be silenced by the mute switch, configure your audio session to honor the mute switch by using either AVAudioSessionCategoryAmbient or AVAudioSessionCategorySoloAmbient.

rob mayoff
  • 375,296
  • 67
  • 796
  • 848
0

I know is an old post, but recently I found a good code in github https://github.com/Rich2k/RBDMuteSwitch and works very well.

This works in ipad with 7.1 (at least).

UPDATE: RDBMuteSwitch does not works since 8.2 and Xcode 6.2 instead I start used SoundSwitch and works fine with 7.1 or greater (i can't test with older devices yet)

This is the answer where I found it.

Community
  • 1
  • 1
Beto
  • 3,438
  • 5
  • 30
  • 37