How to avoid 'auto audio volume decrease' on iphone?

As gamer, I usually listen to podcast with bluetooth while playing games on my iPhone.

I prefer to set audio volume settings to 20% BGM, 50% SFX volume and device master volumes to best-fit for podcast.

So, I can clearly listen to what podcast saying, but not killing all the moods of game by mute.

I’m disturbed when I found my game(in-dev) automatically cut my podcast volume about half
when it launches on my iPhone.

I googled and found someone saying iOS automatically adjust audio to app’s audio data to protect ear and to avoid hearing problem for being exposed to loud sound.

So, I tried change all volumes of sound clips, but it doesn’t help.
And I played some recent games that might be unity-powered, also show same situation,
which I didn’t see this before. ( Tinker Island, Dungeon Warfare, Build Away! and such… )

I’ve been awful experiences with them because I need to change device master volume
every time when I turn on and off games, with sudden loud surprises.

As developer, what I want to do is prevent this from my game.

Is there any particular settings to avoid this?

Is this something new bug of latest Unity?

I noticed this ‘reduced volume’ during 5.4 beta-period(with my in-dev game),

and currently using release version of 5.4.0.3 (no patch applied.) and iPhone 6+ with iOS 9.3.4.

Did someone notice this? Does it bother or not?

I had this problem, VERY irritating. I fixed it by adding a plugin that swizzles AVAudioSession. Here’s my code, I hope it helps.

#import <UIKit/UIKit.h> 
#import <AVFoundation/AVFoundation.h> 
#import <objc/runtime.h>

@interface AudioFix : NSObject 
@end

__strong AudioFix *sharedInstance;

@implementation AVAudioSession(AudioFix)

+ (void)load { 
sharedInstance = [[self alloc] init]; 
} 
- (BOOL)newsetCategory:(NSString *)category 
withOptions:(AVAudioSessionCategoryOptions)options 
error:(NSError * _Nullable *)outError { 
options = AVAudioSessionCategoryOptionMixWithOthers; 
return [self newsetCategory:category withOptions:options error:outError]; 
}

- (id)init { 
if (!(self = [super init])) return nil; 

NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; 
[nc addObserverForName:UIApplicationDidFinishLaunchingNotification 
object:nil 
queue:[NSOperationQueue mainQueue] 
usingBlock:^(NSNotification *note) { 

static dispatch_once_t onceToken; 
dispatch_once(&onceToken, ^{ 

SEL setcategory = @selector(setCategory:withOptions:error:); 
SEL newsetcategory = @selector(newsetCategory:withOptions:error:); 

Method originalMethod = class_getInstanceMethod([self class], setcategory); 
Method extendedMethod = class_getInstanceMethod([self class], newsetcategory); 
method_exchangeImplementations(originalMethod, extendedMethod); 
}); 

}]; 
return self; 
}

@end

@tinklife, @thorn-erikson This is a known issue. Please upvote so they fix it sooner.

Based on @lanestp’s answer, we were finding iOS 9.3.4 was crashing with this. So we modified it thus and it worked. Thanks

#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>
#import <objc/runtime.h>

@implementation AVAudioSession(UnityStartupVolumeFix)

- (BOOL)altSetCategory:(NSString *)category withOptions:(AVAudioSessionCategoryOptions)options error:(NSError * _Nullable *)outError
{
	options = AVAudioSessionCategoryOptionMixWithOthers;
	return [self altSetCategory:category withOptions:options error:outError];
}

+ (void)load
{
	AVAudioSession* instance = [AVAudioSession sharedInstance];
	static dispatch_once_t avAudioSessionHackOnce;
	dispatch_once(&avAudioSessionHackOnce, ^{
		SEL setCategorySelector = @selector(setCategory:withOptions:error:);
		SEL altSetCategorySelector = @selector(altSetCategory:withOptions:error:);
		Method originalMethod = class_getInstanceMethod([instance class], setCategorySelector);
		Method extendedMethod = class_getInstanceMethod([instance class], altSetCategorySelector);
		method_exchangeImplementations(originalMethod, extendedMethod);
	});
}

@end