Search code examples
iphoneipadavaudiorecorderavaudiosession

How to check the type of inputAvailable in iPad?


I am implementing the sound recording functionality in my iPad app. I want to prompt the user to attach his headphone with microphone for better performance.For this I need to check that whether the user has connected the headphone with microphone or not.

In the AVAudioSession there is a method inputIsAvailable.But this method returns 'Yes' for the inbuilt mic of iPad also.So,please suggest how to detect that whether the headphone with mic is connected to the device or not??


Solution

  • Finally,I solved my problem :) The following piece of code is the solution:

    CFStringRef newRoute;
     UInt32 size;
     size = sizeof(CFStringRef);
     OSStatus error = AudioSessionGetProperty(kAudioSessionProperty_AudioRoute, &size, &newRoute);
     if (error)
    {
    
    }
    else
    {
    CFShow(newRoute);
    }
    

    There can be different values for newRoute. If the value of newRoute is 'HeadsetInOut' then the headphones with mic are connected to the iPad.