Bypass iPhone Ring/Silent Switch?

Hi, Im not very familiar with using or building for iOS so im seeking advice about the use of the ‘Ring/Silent switch’, and if possible a way to bypass.

It seems Unity by default mutes audio when this switch is enabled. lm a little confused why it would do this when a) this buttons function is surely just to enable/disable the ringer and b) it also accepts volume and mute instructions from the separate system audio levels.

Many apps bypass the Ring/Silent Switch, why doesnt Unity? Is there a reason why i shouldnt seek to do this? If not how to I do it?

Hello Supdawg,

Did you find how to ignore the mute button on iOS?

Thanks.

I think its possible using AVAudioSession but it became low priority for me so i just put up with it.

This should help

I just wanted to comment on this in case anyone else comes across it Googling, like I did.

The purpose of the mute switch is to mute all sound except important ones like the Alarm, etc. Apple Developer Guidelines: https://developer.apple.com/ios/human-interface-guidelines/interaction/audio/

If your app is a game, you should allow the switch to mute audio. Any games doing this are not “bypassing” the switch, they are failing to implement the recommended guidelines. Apple is not very strict with this requirement though.

Now if your app fits one of the categories that Apple recommends can be permitted to ignore this switch, then you have a valid concern in wanting to bypass what Unity is doing by default.

Weirdly their own app Garage Band ignores this advice… go figure.

I wonder if there is at least a way to detect the mute is on so that you tell the user…

Yes there is: https://www.assetstore.unity3d.com/en/#!/content/56877

Sweet, nice one!

Given that most native apps do not abide by the mute switch this is a little bit ridiculous of an excuse for Unity. Enough apps ignore the mute switch completely that we consistently get user reports that the sound of our game does not work, and unity gives us no real way to address it. Our game engine should not be forcing us into apples recommended product guidelines, especially when the trend started when their first party applications ignored the mute switch. It is now a meaningless toggle that people completely forget is on or exists.

If you cannot properly support iOS in 2021, you are on your way out the door as a game engine.

Wow. What utter BS.

I’m sorry, how ridiculous of me. Our users use any given first-party app and many more daily while getting full sound, then switch to our app and all the sudden it’s silent. Is my point “utter BS” because I would like some amount of consistency, or to not be railroaded by my game engine, or at a bare minimum a built-in functionality for checking the mute switch… or are our users contributing the utter BS when they open our game, Spotify still playing in the background, and they get no sound from our game in particular?

They, of course, assume our app is dysfunctional.

A few apps that bypass the ring switch:
Apple Music
Apple TV
Photos
Podcasts
News
Maps
(If you haven’t caught on yet, none of the default apps abide the ring switch)
Spotify
Pandora
Discord

We’re supposed to tell our users everyone but us is crazy?

@chloelcdev When you make absolute statements like most native apps do not abide by the mute switch” and calling the switch a “meaningless toggle” you will of course get responses that address such a statement.

I’ve already posted a link to Apple’s guidelines on the matter and it clearly states under what conditions and type of audio the switch can be ignored or not, even going so far as to say that “game soundtracks” should be muted.

… most native apps do not abide by the ring switch. I just listed off every first-party pre-installed app that makes sound as ones that, confirmed, do not abide by the ring switch. Even the guidelines you for some reason believe are a smoking gun don’t state that all your sound should be muted.

People switch their device to silent when they want to avoid being interrupted by unexpected sounds like ringtones and incoming message tones. In this scenario, they also want to silence nonessential sounds, such as keyboard clicks, sound effects, game soundtracks, and other audible feedback. When a device is in silent mode, it should play only the audio that people explicitly initiate, like media playback, alarms, and audio/video messaging.

“play only the audio that people explicitly initiate”, which is, some of the sounds in our game. To play any sounds in our game, we need to be able to get around Unity muting all of our audio. What point are you trying to make here by quoting Apple guidelines that don’t say Unity should be muting all our audio?

You’ve answered your own question:
play only the audio that people explicitly initiate, like media playback, alarms, and audio/video messaging.
All those “Native apps” you listed aren’t games. The exceptions are … well, it says it right there, so I won’t be redundant. Just because you want to interpret that to mean audio in a game so that you can claim an exception to the guidelines doesn’t mean that’s the case. Unity should be muting audio because it’s a game engine. If you’re using it to make an iOS non-game app with it, you’re the minority.

And why do I care about Apple guidelines? Because not following them more often than not gets your app rejected.

Games sometimes contain explicitly initiated audio. You don’t seem to care about Apple guidelines, just being right. Honestly, the game engine would probably be doing better right now if people like you didn’t consistently jump in to defend absolute nonsense.

Yeah, I’m going to have to agree with @Carocrazy132 . Even if games are not defined as an exception in the guidelines, doesn’t make it right or intuitive to the user when they expect the game should have audio if their Youtube audio is working.

Any admins from unity available to comment on this?

For anyone that wants a clear answer, without extra fuss:

  1. You need a .mm file that acts as your swift function to enable audio
  2. You need a .cs monobehaviour that calls it in unity.

This is your MM (call it AudioSessionOverride.mm → put it in Assets/Plugins/iOS):

#import <AVFoundation/AVFoundation.h>

extern "C" {
    void EnableAudioWhenMuted() {
           // Set the audio session category to `AVAudioSessionCategoryPlayback`
            [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
            [[AVAudioSession sharedInstance] setActive:YES error:nil];
    }
}

This is your .cs MonoBehaviour (call it: AudioSessionOverrideEnabler.cs)

> using System.Runtime.InteropServices;
> using UnityEngine;
> 
> public class AudioSessionOverrideEnabler : MonoBehaviour
> {
>     [DllImport("__Internal")]
>     private static extern void EnableAudioWhenMuted();
> 
>     private void Start()
>     {
>         #if UNITY_IOS
>         EnableAudioWhenMuted();
>         #endif
>     }
> }

Now just drag and drop the cs script onto any object in your scene to call the thing at start up.
Long live ChatGPT!