Can an iOS App Switch the Device to Silent Mode

Playing sound when device is in silent mode

When in silent mode, unless the user explicitly initiates sound playback, such as media playback, it is in violation of the Human Interface Guidelines (HIG) and is grounds for the app being rejected.

Per the HIG:

Silence. People switch their device to silent to avoid being interrupted by unexpected sounds, such as ringtones and incoming message sounds. They also want nonessential sounds disabled, including keyboard sounds, sound effects, game soundtracks, and other audible feedback. When the device is set to silent, only explicitly initiated sounds should occur, such as audio during media playback, alarms, and audio/video messaging.

If you feel your need is not in violation, see this post for a solution.

How can I detect whether an iOS device is in silent mode or not?

I don't think there is and you probably don't need to directly call an API to detect if the device is muted or not. What you need to know is this:

When playing a sound, you will do something like:

        try AVAudioSession.sharedInstance().setCategory({AVAudioSessionCategory})
try AVAudioSession.sharedInstance().setActive(true)
audioPlayer = try AVAudioPlayer(contentsOfURL: alertSound)
audioPlayer.prepareToPlay()
audioPlayer.play()

In the {AVAudioSessionCategory}, you can specify:

AVAudioSessionCategorySoloAmbient: Your audio is silenced by screen
locking and by the Silent switch

AVAudioSessionCategoryPlayBack: Your Audio continues with the Silent
switch set to silent or when the screen locks

Recognising iPhone Silent Mode

You need to set the appropriate Audio Session Category.

You tell iPhone OS your application’s
audio intentions by designating a
category for your audio session.

For more detail see - Configuring the Audio Session

No audio when iOS ring/silent switch is set to silent mode

audio_service only manages remote control of your app via notifications, lock screens, etc. The audio session is typically managed by the audio player plugin that you use.

If you use just_audio, it will by default set the required category, but if not, you can manually override the category via the audio_session package. e.g. The code below will configure reasonable defaults for a podcast app, including setting the category to playback:

(await AudioSession.instance).configure(const AudioSessionConfiguration.speech());

iOS 9 play audio in silent mode but keep other app's music playback running

The Audio Session Category AVAudioSessionCategoryAmbient will obey the Ring/Silent switch as stated in the documentation -

AVAudioSessionCategoryAmbient
The category for an app in which sound playback is nonprimary—that is, your app can be used successfully with the sound turned off...

... Your audio is silenced by screen locking and by the Silent switch (called the Ring/Silent switch on iPhone).

I suggest trying a better suited category with mixing options like -

[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback 
withOptions:AVAudioSessionCategoryOptionMixWithOthers
error:nil];

AVAudioSessionCategoryPlayback category will ignore the silent switch as mentioned in documentation -

When using this category, your app audio continues with the Silent switch set to silent or when the screen locks.

Disable silent mode on iPhone?

Please search stackoverflow or the web for similar questions before posting a new one, this question has already been covered:

Play sound on iPhone even in silent mode

iphone, how to play sound even in silent or mute mode?

Be careful about overriding the silent mode switch and playing audio. Apple may not like you doing this, depending on the context; if they don't like it, you will fail app review. Is there a good reason to play audio when in silent mode in the context of your app?



Related Topics



Leave a reply



Submit