Igor Igor - 7 days ago 4
iOS Question

Override to use a device's internal microphone only

I need to use the internal iPhone microphone even when a headset with a mic is connected. How do I set it up programmatically?


Excerpted from Apple Docs:

Sets the preferred input port for audio routing.

func setPreferredInput(_ inPort: AVAudioSessionPortDescription?) throws

Setting the preferred input port requests a change to the input audio route. To determine whether the change takes effect, use the currentRoute property. The value of the inPort parameter must be one of the AVAudioSessionPortDescription objects in the availableInputs array. If this parameter specifies a port that is not already part of the current audio route and the app’s session controls audio routing, this method initiates a route change to use the preferred port.You must set a preferred input port only after setting the audio session’s category and mode and activating the session.