@@ -116,19 +116,20 @@ - (AVAudioSessionPortDescription*)getAudioDeviceFromType:(NSString*)type {
116116- (void )handleAudioRouteChange : (NSNotification *) notification {
117117 NSInteger routeChangeReason = [notification.userInfo[AVAudioSessionRouteChangeReasonKey] integerValue ] || 0 ;
118118 AVAudioSession* session = [AVAudioSession sharedInstance ];
119+ NSArray <AVAudioSessionPortDescription *> *inputs = session.currentRoute .inputs ;
120+ NSArray <AVAudioSessionPortDescription *> *outputs = session.currentRoute .outputs ;
119121
120- AVAudioSessionPortDescription *input = [[session.currentRoute.inputs count ] ? session.currentRoute.inputs:nil objectAtIndex: 0 ];
121- AVAudioSessionPortDescription *output = [[session.currentRoute.outputs count ] ? session.currentRoute.outputs:nil objectAtIndex: 0 ];
122- NSString *reason = [self getAudioChangeReason: routeChangeReason];
123-
124- AVAudioSessionRouteDescription *previousRoute = notification.userInfo [AVAudioSessionRouteChangePreviousRouteKey];
125- AVAudioSessionPortDescription *previousInput = [[previousRoute.inputs count ] ? previousRoute.inputs:nil objectAtIndex: 0 ];
126- AVAudioSessionPortDescription *previousOutput = [[previousRoute.outputs count ] ? previousRoute.outputs:nil objectAtIndex: 0 ];
122+ if (inputs && inputs.count > 0 ) {
123+ AVAudioSessionPortDescription *input = [[inputs count ] ? inputs:nil objectAtIndex: 0 ];
124+ AVAudioSessionPortDescription *output = [[outputs count ] ? outputs:nil objectAtIndex: 0 ];
125+ NSString *reason = [self getAudioChangeReason: routeChangeReason];
127126
128- NSLog (@" [IIMobile - RNAudioManager][handleRouteChange] with reason %@ from INPUT %@ to %@ " , reason, previousInput.portType , input.portType );
129- NSLog (@" [IIMobile - RNAudioManager][handleRouteChange] with reason %@ from OUTPUT %@ to %@ " , reason, previousOutput.portType , output.portType );
127+ AVAudioSessionRouteDescription *previousRoute = notification.userInfo [AVAudioSessionRouteChangePreviousRouteKey];
128+ AVAudioSessionPortDescription *previousInput = [[previousRoute.inputs count ] ? previousRoute.inputs:nil objectAtIndex: 0 ];
129+ AVAudioSessionPortDescription *previousOutput = [[previousRoute.outputs count ] ? previousRoute.outputs:nil objectAtIndex: 0 ];
130130
131- if (input != nil ) {
131+ NSLog (@" [IIMobile - RNAudioManager][handleRouteChange] with reason %@ from INPUT %@ to %@ " , reason, previousInput.portType , input.portType );
132+ NSLog (@" [IIMobile - RNAudioManager][handleRouteChange] with reason %@ from OUTPUT %@ to %@ " , reason, previousOutput.portType , output.portType );
132133 if (!([input.portType isEqualToString: AVAudioSessionPortBuiltInMic] && speakerEnabled)) {
133134 [RNEventEmitterHelper emitEventWithName: @" audioRouteChanged"
134135 andPayload: @{
0 commit comments