0

I need to check if my iPhone has a headphone port or not. I checked if the headphone is connected using the following code

!AVAudioSession.sharedInstance().currentRoute.outputs.filter { $0.portType == AVAudioSession.Port.headphones }.isEmpty

But it shows me that headphone is connected or not. But iPhoneX does not have any earphone port.

Is there any way to differentiate between "headphone not available" and "headphone not connected"?

Any help will be appreciated.

Chitra Khatri
  • 1,260
  • 2
  • 14
  • 31
Chanchal Chauhan
  • 1,530
  • 13
  • 25

1 Answers1

0

You should not look for the feature. You should check the device model. Here you have a handy UIDevice extension to do that.

https://stackoverflow.com/a/26962452/4076101

That way, if you get an iPhone 7(+) or posterior device, you can assure you won't have a headphone port (although you won't be able to know if a Lightning to 3,5mm adapter is connected.

Manu Mateos
  • 174
  • 1
  • 10