5

Possible Duplicate:
Mute/Silence an iOS device programmatically?

I need to turn off the device volume programmatically. Does anyone know a way?

So far I have discovered, that maybe i can use AudioSessionSetProperty() function, and use the property "kAudioSessionProperty_CurrentHardwareOutputVolume", but this property is only read only. SO i am not sure if this will work:

float value = 0.0f;
AudioSessionSetProperty(kAudioSessionProperty_CurrentHardwareOutputVolume, sizeof(float), &value);

There are already apps in the App-Store that does this, e.g. AutoSilent:

http://itunes.apple.com/nl/app/autosilent/id474777148?mt=8

Community
  • 1
  • 1
revolutionary
  • 3,314
  • 4
  • 36
  • 53

2 Answers2

3

You can't do this with iOS. The only way to mute an iOS device is by using the hardware switch. You can detect it and mute your app accordingly, but can't mute the entire device from your app.

Community
  • 1
  • 1
Adam
  • 26,549
  • 8
  • 62
  • 79
  • I dont think you are right, as there are apps in the appstore that does that...e.g. AutoSilent see http://itunes.apple.com/nl/app/autosilent/id474777148?mt=8 – revolutionary Jun 27 '12 at 00:59
  • I guess they use some private API for this, which is not allowed. How did they get those apps accepted? I dont know. I guess they are just lucky as the app submission system is kinda lotto :-) – Adam Jun 27 '12 at 05:30
0

See this question: How to disable iOS System Sounds

And this question: Mute/Silence an iOS device programmatically?

They say there that it is possible though you have to use a private framework called the Celestial framework. You would use AVSystemController to silence the phone like so:

[[AVSystemController sharedAVSystemController] setVolumeTo:0 forCategory:@"Ringtone"];

The use of private frameworks in your app will cause it to be rejected by apple, so I don't recommend using it. Some believe that using private frameworks in your app could potentially be allowed by Apple initially (if they miss it), but it will soon be removed from the App Store when they realize that you are utilizing a private framework.

Hope this helps!

Community
  • 1
  • 1
pasawaya
  • 11,515
  • 7
  • 53
  • 92
  • I think there must be a non-private way to do this, because the only things these apps are doing e.g. AutoSilent and SilentAlert, is switching the device volume off..... I dont belive that Apple could miss that when this is the very purpose of these apps. – revolutionary Jun 27 '12 at 02:01
  • 1
    They approved fake "Counter Strike" game at least two times. So yes, i think they could miss that too. – Adam Jun 27 '12 at 14:10