When iOS17 has a bug and cannot record audio, play the audio to a Bluetooth device

let session = AVAudioSession.sharedInstance() do {

        try session.setCategory(AVAudioSession.Category.playback)
        try session.setActive(true)
        //playAndRecord <AVAudioSessionPortDescription: 0x2828dc2b0, type = Speaker; name = 扬声器; UID = Speaker; selectedDataSource = (null)>
        //playback <AVAudioSessionPortDescription: 0x28204c1a0, type = BluetoothA2DPOutput; name = M2; UID = 00:02:5C:22:22:11-tacl; selectedDataSource = (null)>
        print(session.currentRoute.outputs)


    } catch {
        print(error)
    }

when I ssession.setCategory(AVAudioSession.Category.playback) audio play output a2dp ble devices. session.currentRoute.outputs print bellow `<AVAudioSessionPortDescription: 0x28204c1a0, type = BluetoothA2DPOutput; name = M2; UID = 00:02:5C:22:22:11-tacl; selectedDataSource = (null)> when I ssession.setCategory(AVAudioSession.Category.playAndRecord) output <AVAudioSessionPortDescription: 0x2828dc2b0, type = Speaker; name = 扬声器; UID = Speaker; selectedDataSource = (null)> BluetoothA2DPOutput is gone. but it is normal in ios15-16.

Is there any solution? I want to record audio and play music at the same time. And the music is output from the Bluetooth speaker

    AVAudioSession *audioSession = [AVAudioSession sharedInstance];
   // 设置为内置麦克风采集
   [audioSession setCategory:AVAudioSessionCategoryPlayAndRecord mode:AVAudioSessionModeVideoRecording options:nil error:nil];
   
    // 切换输入麦克风
    AVAudioSessionPortDescription *builtInMicPort = nil;
    for (AVAudioSessionPortDescription *portDescription in audioSession.availableInputs) {
        if ([portDescription.portType isEqualToString:AVAudioSessionPortBuiltInMic]) {
            builtInMicPort = portDescription;
            break;
        }
    }

    if (builtInMicPort) {
        NSError *inputError = nil;
        [audioSession setPreferredInput:builtInMicPort error:&inputError];

        if (inputError) {
            NSLog(@"切换输入麦克风失败:%@", inputError);
        }else{
            NSLog(@"内置麦克风");
        }
    } else {
        NSLog(@"找不到内置麦克风");
    }
    [audioSession setActive:YES error:nil];

work normal

When iOS17 has a bug and cannot record audio, play the audio to a Bluetooth device
 
 
Q