From 96ebd2542ea3890f0facf99a191821b30556e7ec Mon Sep 17 00:00:00 2001 From: Nagy Szilard Date: Fri, 1 Apr 2022 15:20:08 +0300 Subject: [PATCH] #540 fix to not change the setted audio route when getAudioRoute called --- ios/RNCallKeep/RNCallKeep.m | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/ios/RNCallKeep/RNCallKeep.m b/ios/RNCallKeep/RNCallKeep.m index 0a1a3ff5..2f888359 100644 --- a/ios/RNCallKeep/RNCallKeep.m +++ b/ios/RNCallKeep/RNCallKeep.m @@ -455,6 +455,21 @@ + (void)setup:(NSDictionary *)options { } NSArray *ports = [RNCallKeep getAudioInputs]; + + BOOL isCategorySetted = [myAudioSession setCategory:AVAudioSessionCategoryPlayAndRecord withOptions:AVAudioSessionCategoryOptionAllowBluetooth | + AVAudioSessionCategoryOptionAllowBluetoothA2DP | AVAudioSessionCategoryOptionAllowAirPlay error:&err]; + if (!isCategorySetted) + { + NSLog(@"setCategory failed"); + [NSException raise:@"setCategory failed" format:@"error: %@", err]; + } + BOOL isCategoryActivated = [myAudioSession setActive:YES error:&err]; + if (!isCategoryActivated) + { + NSLog(@"setActive failed"); + [NSException raise:@"setActive failed" format:@"error: %@", err]; + } + for (AVAudioSessionPortDescription *port in ports) { if ([port.portName isEqualToString:inputName]) { BOOL isSetted = [myAudioSession setPreferredInput:(AVAudioSessionPortDescription *)port error:&err]; @@ -521,14 +536,6 @@ + (NSArray *) getAudioInputs AVAudioSession* myAudioSession = [AVAudioSession sharedInstance]; - BOOL isCategorySetted = [myAudioSession setCategory:AVAudioSessionCategoryPlayAndRecord withOptions:AVAudioSessionCategoryOptionAllowBluetooth | - AVAudioSessionCategoryOptionAllowBluetoothA2DP | AVAudioSessionCategoryOptionAllowAirPlay error:&err]; - if (!isCategorySetted) - { - NSLog(@"setCategory failed"); - [NSException raise:@"setCategory failed" format:@"error: %@", err]; - } - BOOL isCategoryActivated = [myAudioSession setActive:YES error:&err]; if (!isCategoryActivated) {