You need read AudioSessionProgrammingGuide
You can get the current audio 'route' by calling AudioSessionGetProperty with the kAudioSessionProperty_AudioRoute property. This gives you a string such as "Headphone" or "Speaker" and play audio file receptively 'route' value
CFStringRef route;
UInt32 propertySize = sizeof(CFStringRef);
AudioSessionInitialize(NULL, NULL, NULL, NULL);
AudioSessionGetProperty(kAudioSessionProperty_AudioRoute, &propertySize, &route);
NSLog(@"%@ %@",route,kAudioSessionInputRoute_Headphone);
NSLog(@"%ld",CFStringGetLength(route));
if ([(__bridge NSString *)route isEqualToString:@"Headphone"])
{
// play audio sound
}
else
{
// not play audio sound
}
I hope it help you