views:

1810

answers:

2

I've been searching and can't seem to find the answer elsewhere - is it possible to detect if the iPod Touch/iPhone has any headphones or other accessories connected to it?

I'm building an app that requires a microphone, and need to know if the "iSomething" has one connected or not, either via the dock connection, or using the headphone port, such as with the inline headphone/microphone accessory from Apple.

Edited to add the bit about the types of accessories connected.

A: 

To determine if the device has a built in microphone you can just go by [UIDevice currentDevice].model to see if it's an iPhone or a 2nd generation iPod Touch. As far as a third-party microphone plugged into the dock connector, this is not possible in the current 2.2.1 SDK, but it may be in a later version :)

Andy Bourassa
It's better to test for feature support separate from device type.
Alex Reynolds
+7  A: 

Finally found it - After initializing the Audio Session object, - AudioSessionInitialize() - you can make a call to AudioSessionGetProperty, and get the value of kAudioSessionProperty_AudioInputAvailable.

AudioSessionInitialize(NULL, NULL, NULL, NULL);    
UInt32 propertySize, micConnected;
    AudioSessionGetProperty(kAudioSessionProperty_AudioInputAvailable, &propertySize, &micConnected);
    [self updateMicStatus:micConnected]; // user-created method

According to the docs for Audio Session Services, this should be used rather than using the device model (iPhone vs. iPod Touch) to determine if an audio input is available to use. You can also set up a callback function to monitor changes to this property via AudioSessionAddPropertyListener().

Not sure yet if this property also applies to devices connected via the Dock connector, but it appears to work for the headphone jack.

joshbuhler
For some reason this does not work for me. On an iPod Touch 2nd gen without headphones connected it returns TRUE...
Dimitris