I want to make an application which creates sound, music, or system sound when an iPhone is in silent mode. Is it possible to play any type of sound whether music or system tones when it is silent mode?
-
15If I were the user, I would be tipped off by that "feature"... After all, the user who puts the phone in silent mode probably hopes the phone stays quiet. – William Niu Sep 18 '10 at 05:40
-
3I thought the purpose of silent mode was to make the phone stay **silent**? – Yi Jiang Sep 18 '10 at 05:42
-
if there were important numbers that need to be picked then it is helpful – Pankaj Kainthla Sep 18 '10 at 05:43
-
1@pankaj in that case, have you tried the other way around: put all "unimportant" calls in silent? This might be more feasible. – William Niu Sep 18 '10 at 05:48
-
1If you mean the ring/silent switch, I thought there already were games that played game sounds with that switch set to silent. The volume control rocker settings works independently from the ringer switch. But there's no way to monitor who's calling using public SDK APIs. – hotpaw2 Sep 18 '10 at 05:57
-
1is there any source code to play sound on silent mode – Pankaj Kainthla Sep 18 '10 at 10:01
-
it will be good if user's phone is silent and there is a very important call ,then the phone can ring itself when same caller calls multiple times which would mean that the call was important – Pankaj Kainthla Feb 03 '11 at 07:20
-
Seems "evil". Honestly I wish Apple didn't allow this at all. – Justin Morgan Feb 04 '11 at 06:43
-
15I wanted to chime in with a thought on why this is perfectly good UX (if un-abused). The simple examples are alarm apps and apps in which the user explicitly causes a video to play. It's annoying to physically communicate to an app that it should present a video to you only to recall that you have the device on mute. Mute is for hushing *unscheduled* interruptions, such as phone calls, texts, and other alerts. It is not helpful to equate it to disconnecting your speakers... Especially when you can simply put volume at zero to achieve that. – Chris Trahey May 01 '13 at 08:17
-
3I'd like to go with ctrahey here ; I'm making a radio app, if the user presses "Play", he expects sound to come out. I don't want him to have to unmute his phone in order to listen to the radio. And on top of this, he won't be disturbed by *unscheduled* sounds. I think this is totally acceptable, opposing what @WilliamNiu said – Gil Sand Jun 20 '16 at 15:05
8 Answers
It's not advisable, but who am I to say you can't do it. You may have a good reason to be playing sound.
If you are using Audio Sessions, then include <AVFoundation/AVFoundation.h>
at the start of your file and
[[AVAudioSession sharedInstance]
setCategory: AVAudioSessionCategoryPlayback
error: nil];
should do the trick. Note if you play music or sounds, then iPod playback will be paused.
Once this has been done, probably somewhere in the initialization of one of your classes that plays the sounds, you can instantiate sounds like this:
// probably an instance variable: AVAudioPlayer *player;
NSString *path = [[NSBundle mainBundle] pathForResource...];
NSURL *url = [NSURL fileURLWithPath:path];
player = [[AVAudioPlayer alloc] initWithContentsOfURL:url];
When that's done, you can play with it any time you want with:
[player play]; // Play the sound
[player pause]; // Pause the sound halfway through playing
player.currentTime += 10 // skip forward 10 seconds
player.duration // Get the duration
And other nice stuff. Look up the AVAudioPlayer Class reference.

- 37,241
- 25
- 195
- 267

- 2,015
- 2
- 16
- 19
-
-
Hi guys, first thanks cool_me5000 for the answer. In my case the sound sounds when the app is in background (with volume to a minimum) but if the app is in foreground (with volume to a minimum) the sound doesn't sound. I'm testing in a iPod touch 4 generation (I said this because it hasn't silent switch). Do you know what can I change to achieve that the app sounds in both situations? – xarly Jul 25 '13 at 08:36
-
1In case you end up here, because this solution won't work on iPad, but only on iPhone: I just had that issue when setting the `AVAudioSession` category before presenting a `AVPlayerViewController`. If I set the category in the completion block of the `presentViewController` call (and before actually calling `play()`) it works fine on both device families. – Jerrot Feb 10 '17 at 14:44
Yes you can play sound when the phone is set to vibrate. Simply use the AVAudioPlayer class.
By default, playing an Audio Session sound will ~not~ respect the setting of the mute switch on the iPhone. In other words, if you make a call to play a sound and the silent (hardware) switch on the iPhone is set to silent, you’ll still hear the sound.
This is what you want. So now you know that playing an Audio Session when your phone is in silent mode will still play the sound you just need to know how to create an audio session to play the sound, like so: taken from this website: http://iosdevelopertips.com/audio/playing-short-sounds-audio-session-services.html
SystemSoundID soundID;
NSString *path = [[NSBundle mainBundle]
pathForResource:@"RapidFire" ofType:@"wav"];
AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath:path],&soundID);
AudioServicesPlaySystemSound (soundID);
For this to work, you will need to import header file, and also add the AudioToolbox.framework to your project.
And that's it.
So from this answer you now know that you can play sound while the phone is on vibrate. You don't need extra or special code to allow you to do this functionality as it already does that by default.
Pk
-
2
-
1I don't currently have an answer at this moment in time as I haven't had a need to do this yet. Also, this question is 6 years old, if anyone has an answer for iOS 9, feel free to edit. – Pavan Oct 27 '16 at 04:42
-
I know this is an old post,but I now have a similar problem with a medical application that has to alert staff even if the phone is in Silent mode. I am using iOS 10.2 devices and the following code, partially taken from Apple doc works in Debug Mode while the telephone is in Silent mode but does not work when running in a non-debug mode. – men Jan 26 '17 at 11:48
-
AVAudioSession *audioSession = [AVAudioSession sharedInstance]; NSError *setCategoryError = nil; BOOL success = [audioSession setCategory:AVAudioSessionCategoryPlayback error:&setCategoryError]; NSError *activationError = nil; success = [audioSession setActive:YES error:&activationError]; CFURLRef soundFileURLRef; soundFileURLRef = CFBundleCopyResourceURL (CFBundleGetMainBundle(),CFSTR("dings"),CFSTR("caf"),NULL); AVAudioPlayer *player = [[AVAudioPlayer alloc] initWithContentsOfURL:(__bridge NSURL * _Nonnull)(soundFileURLRef) error:nil]; [player play]; – men Jan 26 '17 at 11:53
-
This doesn't solve synth apps which are using synth/oscillator instead of playing an audio file. – pete Aug 07 '20 at 23:06
-
EDIT: Actually it still works even if only using AVAudioEngine. Make a AVAudioSession refering to the shared() one and set category on that one; it works – pete Aug 07 '20 at 23:13
Works on iOS 6 and above
NSError *setCategoryErr = nil;
NSError *activationErr = nil;
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:&setCategoryErr];
[[AVAudioSession sharedInstance] setActive:YES error:&activationErr];

- 22,616
- 10
- 116
- 130
-
1in Swift `do { try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback) try AVAudioSession.sharedInstance().setActive(true) } catch let error as NSError { // report error }` – Guy Apr 15 '16 at 20:14
Just put this in your viewDidLoad
:
UInt32 sessionCategory = kAudioSessionCategory_MediaPlayback;
AudioSessionSetProperty (kAudioSessionProperty_AudioCategory,
sizeof(sessionCategory), &sessionCategory);

- 12,527
- 15
- 69
- 90
For playing a sound in silent mode and even when it goes to background, try this:
Put this code in application:didFinishLaunchingWithOpitons:
[[AVAudioSession sharedInstance] setDelegate:self];
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
[[AVAudioSession sharedInstance] setActive:YES error:nil];
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
and this code in applicationDidEnterBackground:
[[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:NULL];
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
Also setup a background mode of Playing Audio/Air Play and include AVFoundation header.

- 1,030
- 2
- 10
- 20
for Objective C, you could play system sound with following code:
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
*The system path could be modified.*
NSString *path = @"/System/Library/Audio/UISounds/begin_record.caf";
NSURL *url = [NSURL fileURLWithPath:path];
player = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:nil];
[player play];

- 21
- 7
Swift - Call this function before playing your audio/video to force playback when the phone is on silent. This also silences other audio that is currently playing.
You can change .duckOthers
to .mixWithOthers
if you don't want to silence other audio.
func setupAudio() {
let audioSession = AVAudioSession.sharedInstance()
_ = try? audioSession.setCategory(AVAudioSessionCategoryPlayback, with: .duckOthers)
_ = try? audioSession.setActive(true)
}

- 13,044
- 8
- 95
- 91