AVAudioSession : 麦克风耳机作为输入,iphone 扬声器作为输出

AVAudioSession : microphone headphone as input and iphone speaker as output

使用 iOS10 可以管理 AUdioSession,但我无法在音频通过 iphone 扬声器输出时将耳机麦克风保持为输入。

下面的 'overrideOutputAudioPort' 方法也将输入音频端口覆盖为 iphone 麦克风

let session = AVAudioSession.sharedInstance()
do {
  try session.setCategory(AVAudioSessionCategoryPlayAndRecord)
  try! session.overrideOutputAudioPort(.speaker)  
} catch {
}

有什么办法可以让耳机一直作为输入吗?

我怎么理解 this Apple documentation,使用 AVAudioSession 是不可能的:

If a headset is plugged in at the time you set this property’s value to kAudioSessionOverrideAudioRoute_Speaker, the system changes the audio routing for input as well as for output: input comes from the built-in microphone; output goes to the built-in speaker.