AudioSessionSetProperty
and AudioSessionGetProperty
are deprecated as of iOS 7. Use AVAudioSession
instead.
You can use its availableInputs
property to get a list of what's available and iterate through them to find one that looks like a microphone, like this:
NSArray *availableInputs = [[AVAudioSession sharedInstance] availableInputs];
BOOL micPresent = false;
for (AVAudioSessionPortDescription *port in availableInputs)
{
if ([port.portType isEqualToString:AVAudioSessionPortBuiltInMic] ||
[port.portType isEqualToString:AVAudioSessionPortHeadsetMic])
{
micPresent = true;
}
}
if (micPresent)
{
// Do something cool
}
else
{
// No mic present - show alert
}
Alternatively, if you just want any input at all, and don't care if it's a mic or a line-in, you can just do:
if ([[AVAudioSession sharedInstance] inputAvailable];
{
// Do something cool
}
else
{
// No input present - show alert
}