Skip to content

Commit

Permalink
fix(ios): The getAudioRoutes changes the selected audio route #540
Browse files Browse the repository at this point in the history
  • Loading branch information
rcidt committed Mar 31, 2022
1 parent 51f8d9a commit a51cb74
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions ios/RNCallKeep/RNCallKeep.m
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,21 @@ + (void)setup:(NSDictionary *)options {
}

NSArray *ports = [RNCallKeep getAudioInputs];

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

BOOL isCategoryActivated = [myAudioSession setActive:YES error:&err];
if (!isCategoryActivated)
{
NSLog(@"[RNCallKeep][setAudioRoute] 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];
Expand Down Expand Up @@ -570,20 +585,6 @@ + (NSArray *) getAudioInputs

AVAudioSession* myAudioSession = [AVAudioSession sharedInstance];

BOOL isCategorySetted = [myAudioSession setCategory:AVAudioSessionCategoryPlayAndRecord withOptions:AVAudioSessionCategoryOptionAllowBluetooth error:&err];
if (!isCategorySetted)
{
NSLog(@"[RNCallKeep][getAudioInputs] 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

0 comments on commit a51cb74

Please sign in to comment.