AVAudioSession currentRoute.outputs not working in background in iOS 16

In my app, which gives voice prompts and sound warnings while driving, I test if the audio session is connected to CarPlay in order to use CarPlay settings for AVAudioSession by doing:

BOOL found = NO;
for (AVAudioSessionPortDescription * portDescr in [AVAudioSession sharedInstance].currentRoute.outputs) {
    if ([portDescr.portType isEqualToString:AVAudioSessionPortCarAudio])
         found = YES;
}

This has worked for several years. But now, in iOS 16, when the app is in background, it won't detect that the iPhone is connected to CarPlay most of the times by using this method. Therefore, I will set up the audio session in a way which won't play any sound to the user.

I have seen this happening in other apps such as Google Maps. So my guess is that something is not working in iOS 16 an AVAudioSession in background.

Has anyone experienced this? Any workaround?

I tried notifications to detect a change in a route, but sometimes I wouldn't get the notification if the app was in background when connecting to CarPlay. So this workaround didn't work either.

Any ideas?

Thank you.

Did you figure out how to fix this? I'm also facing a similar issue, I try to get the AVAudioSession.sharedInstance().currentRoute.outputs but I'm just receiving an empty array, if I try it when the app is running, then I always receive the iPhone speaker in the outputs array.

AVAudioSession currentRoute.outputs not working in background in iOS 16
 
 
Q