I want to detect specially on iPad's if there is ear piece available or not.
For example - I can detect if the iOS device hasTourch or not using AVFoundation so is there any way to detect ear piece availability.
I want to detect specially on iPad's if there is ear piece available or not.
For example - I can detect if the iOS device hasTourch or not using AVFoundation so is there any way to detect ear piece availability.
1) If you want to check if Ear piece (Receiver speaker) is available on device
You can identify this by simply identifying if Device is iPhone.
UIDevice.current.userInterfaceIdiom == .phone
in iOS prottype
AVAudioSessionPortBuiltInReceiver
is there for builtInreceriver speaker. and according to apple's documentation, This is available only on iPhone device. So there is no need to check for anything else, If its iPhone, You have Ear piece and if its not iPhone (on ipad) it don't have ear piece.2) If you want to check if head phone is connected or not:
You can use currentroute of share audio session to check if headset is connected or not: here is sample function in swift 3.0
You should also monitor its status by listening for route change:
here is sample code for handler of notification setup above:
You can check if built-in-mic is available.
Another way to to check if current device is iPhone.
Swift 3:
Reference:
Apple document: https://developer.apple.com/reference/avfoundation/avaudiosessionportdescription/1669281-output_port_types
The short and simplest way is to check via
contains
.One liner Swift 4+ solution to:
Detect if built-in-mic is available
Detect if the Ear piece (Receiver speaker) is available
Check for