4

I am using AVAudioSession to detect whether an external mic is attached to the device I'm using (an iPad 2 in this case). However, the below call is returning nil when I have an external mic attached, and when I don't.

NSArray *availableInputs = [[AVAudioSession sharedInstance] availableInputs];
AVAudioSessionPortDescription *port = [availableInputs objectAtIndex:0];

I would have assumed that when the mic is not attached this would return a list including the internal mic alone, with the external microphone attached it would return a list including the internal mic and the external mic.

This thread indicates that it should be returning these sort of results (with an error in this case, but that seems irrelevant), so I'm confused as to why I'm not getting the correct output. Perhaps there's a flag that needs to be set to show that I'm using multi-route audio.

Any help would be appreciated.

Community
  • 1
  • 1
  • 1
    I believe you have disabled the microphone access on your device got your specific application. Go to settings > Privacy > Microphone > and then toggle the button to on for your application – Pavan Jan 30 '14 at 03:11
  • 2
    Make sure the application has an audio session category set to active, that supports audio input. Otherwise it will always return nil. – Bamsworld Jan 30 '14 at 06:34
  • Yep, it was an audio session category problem. Facepalm.. Thanks guys! – Shane McQuillan Jan 30 '14 at 17:23
  • 1
    @ShaneMcQuillan I've run into same problem! How to set session category to active? Please help. Thanks! – Hyder Oct 16 '15 at 07:28
  • Late but still if any one needs @hyd00 `NSError *sessionError;` `[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryRecord error:&sessionError];` – souvickcse Jul 13 '17 at 07:00

0 Answers0