Skip to content

Commit

Permalink
Fix: (ios) do not modify audio settings when getting audio routes
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmitry Ovcharov committed Jun 17, 2022
1 parent 639b525 commit a24d50e
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions ios/RNCallKeep/RNCallKeep.m
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,25 @@ + (void)setup:(NSDictionary *)options {
return;
}

NSString *category = [myAudioSession category];
NSUInteger options = [myAudioSession categoryOptions];
if(![category isEqualToString:AVAudioSessionCategoryPlayAndRecord] && (options != AVAudioSessionCategoryOptionAllowBluetooth) && (options !=AVAudioSessionCategoryOptionAllowBluetoothA2DP))
{
BOOL isCategorySetted = [myAudioSession setCategory:AVAudioSessionCategoryPlayAndRecord withOptions:AVAudioSessionCategoryOptionAllowBluetooth error:&err];
if (!isCategorySetted)
{
NSLog(@"setCategory failed");
[NSException raise:@"setCategory failed" format:@"error: %@", err];
}
}

BOOL isCategoryActivated = [myAudioSession setActive:YES error:&err];
if (!isCategoryActivated)
{
NSLog(@"[RNCallKeep][getAudioInputs] setActive failed");
[NSException raise:@"setActive failed" format:@"error: %@", err];
}

NSArray *ports = [RNCallKeep getAudioInputs];
for (AVAudioSessionPortDescription *port in ports) {
if ([port.portName isEqualToString:inputName]) {
Expand Down Expand Up @@ -576,27 +595,6 @@ + (NSArray *) getAudioInputs
NSString *str = nil;

AVAudioSession* myAudioSession = [AVAudioSession sharedInstance];
NSString *category = [myAudioSession category];
NSUInteger options = [myAudioSession categoryOptions];


if(![category isEqualToString:AVAudioSessionCategoryPlayAndRecord] && (options != AVAudioSessionCategoryOptionAllowBluetooth) && (options !=AVAudioSessionCategoryOptionAllowBluetoothA2DP))
{
BOOL isCategorySetted = [myAudioSession setCategory:AVAudioSessionCategoryPlayAndRecord withOptions:AVAudioSessionCategoryOptionAllowBluetooth error:&err];
if (!isCategorySetted)
{
NSLog(@"setCategory failed");
[NSException raise:@"setCategory failed" format:@"error: %@", err];
}
}

BOOL isCategoryActivated = [myAudioSession setActive:YES error:&err];
if (!isCategoryActivated)
{
NSLog(@"[RNCallKeep][getAudioInputs] setActive failed");
[NSException raise:@"setActive failed" format:@"error: %@", err];
}

NSArray *inputs = [myAudioSession availableInputs];
return inputs;
}
Expand Down Expand Up @@ -894,7 +892,9 @@ - (void)configureAudioSession
#endif

AVAudioSession* audioSession = [AVAudioSession sharedInstance];
[audioSession setCategory:AVAudioSessionCategoryPlayAndRecord withOptions:AVAudioSessionCategoryOptionAllowBluetooth error:nil];
[audioSession setCategory:AVAudioSessionCategoryPlayAndRecord
withOptions:AVAudioSessionCategoryOptionAllowBluetooth | AVAudioSessionCategoryOptionAllowBluetoothA2DP
error:nil];

[audioSession setMode:AVAudioSessionModeDefault error:nil];

Expand Down

0 comments on commit a24d50e

Please sign in to comment.