Mute/Silence an iOS device programmatically?
Asked Answered
S

1

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!

Swanson answered 29/4, 2012 at 10:11 Comment(5)
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.Xiaoximena
#7829458Orpiment
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.Swanson
Hmm, @Orpiment , 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.Swanson
If you have got any solution than please share it here, so it may help to others also.Nagana
S
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

Sellars answered 27/1, 2015 at 23:22 Comment(1)
Deprecated in iOS 8xOppilate

© 2022 - 2024 — McMap. All rights reserved.