5

I'm trying to mute the device's ringer from within my app, but for some reason using AVSystemController like in this answer ( How to disable iOS System Sounds ) won't let me silence the device ALL the way down.. it drops it to a volume of 1 bar, but not completely silent.

I know it can be done, probably with a private API like AVSystemController, and I know that Apple will still approve the app if the user expects this kind of functionality from the app (since there are already 2 apps I found in the App Store which mutes the device programmatically with no need of jailbreaking or anything like that).

Those apps actually do something better - they actually toggle the actual mute, not just decreasing the volume to zero.

Does anyone know the way this is being done?

Any help will be greatly appreciated! Thanks!

Community
  • 1
  • 1
itai alter
  • 591
  • 1
  • 7
  • 22
  • This sounds a lot as if you are attempting something, most users won't like to be done by an App without their consent. I am praying to Steve that this is not doable. – Till Apr 29 '12 at 10:14
  • 1
    http://stackoverflow.com/questions/7828958/can-an-ios-app-switch-the-device-to-silent-mode – Roshit Apr 29 '12 at 10:19
  • 1
    What I'm trying to do is to automatically silence your device when you go into a meeting (plz don't steal the idea). Users will love it, and please don't use Steve's name in vain. – itai alter Apr 29 '12 at 10:20
  • Hmm, @Roshit , so you're saying I need to submit a request to make that API public? I don't think it's a good idea because it does open the door for mischief, but I believe that Apple WILL approve my app even if it uses a private API... does Anyone have an actual helpful answer please? thanks. – itai alter Apr 29 '12 at 10:26
  • 2
    If you have got any solution than please share it here, so it may help to others also. – Muhammad Rizwan Apr 25 '13 at 12:31

1 Answers1

1

This worked for me, I have a button that toggles sound on and off in a game. I set the float to 10 when I want sound on and 0 when I want sound off.

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

Update:

Another option that is still working with iOS 9.1

float vol = [[AVAudioSession sharedInstance] outputVolume];
NSLog(@"output volume: %1.2f dB", 20.f*log10f(vol+FLT_MIN));

For Swift:

let volume = AVAudioSession.sharedInstance().outputVolume   
print("Output volume: \(volume)")

Sources for updates answer: Get System Volume iOS

Community
  • 1
  • 1
MSU_Bulldog
  • 3,501
  • 5
  • 37
  • 73