I need to apply headphone-specific scenario only when headphones are the sole active playback device in my iOS audio app.
Problem that there is no absolute way to definitively understand that headphones are the sole active playback device
AVAudioSession.currentRoute.outputs portTypes don't guarantee headphones:
let session = AVAudioSession.sharedInstance()
let outputs = session.currentRoute.outputs
let headphonesOnly = outputs.count == 1 &&
(outputs.first?.portType == .headphones ||
outputs.first?.portType == .bluetoothA2DP ||
outputs.first?.portType == .bluetoothHFP ||
outputs.first?.portType == .bluetoothLE)
The issue in code above that listed bluetooth profiles (A2DP, HFP, LE) can be used by any audio device, not only headphones
Is there any public API on iOS that can:
-
Distinguish Bluetooth headphones vs Bluetooth speakers when both use A2DP/LE?
-
Expose the user’s “Device Type” classification (headphones / speaker / car stereo, etc.) that is shown in Settings → Bluetooth → Device Type?
-
Provide a more reliable way to know “this route is definitely headphones” for A2DP devices, beyond portType and portName string heuristics?