1

I am looking for a way of showing a list of available audio outputs like callkit does - it shows ActionSheet with devices listed - see photo (normal call with audio button touched while bluetooth speaker and headphones connected).

normal call with audio button touched while bluetooth speaker and headphones connected

Is there any possibility to show this action sheet using piece of code? Right now my searchings about enumerating and showing audio outputs gets me to enumerate inputs and map it in some way or user multiRoute category (see List available output audio target AVAudioSession). Maybe there is some more native/easy way ?

gwyhyr
  • 51
  • 6

2 Answers2

0

I tried to do this but with no luck. The closest solution I figured is to detect if a headphone is connected using the following:

extension AVAudioSession {
    static var connectedHeadphones: AVAudioSessionPortDescription? {
        return sharedInstance().currentRoute.outputs.first(where: { $0.isHeadphones })
    }
}

extension AVAudioSessionPortDescription {
    var isHeadphones: Bool {
        return portType == AVAudioSession.Port.headphones || portType == AVAudioSession.Port.bluetoothA2DP
    }
}

and then set it to the AVAudioSession:

try session.setPreferredInput(connectedHeadphones)

Mosbah
  • 1,347
  • 1
  • 14
  • 28
  • This is not answer for my question. Here - https://stackoverflow.com/questions/12264697/how-to-list-available-audio-output-route-on-ios - you have a list of potential output devices. Headphone is only one of them and I have already handled it with the way you wrote. I was hoping there is some other way to do it than manually create a ActionSheet with a list of connected devices. – gwyhyr Jan 10 '19 at 21:54
  • 1
    The only thing you can change in callKit UI is your app icon via `configuration.iconTemplateImageData`, there is no other option to change the UI as it is handled by iOS. – Mosbah Jan 11 '19 at 09:14
0

OK, after some time I can answer for my question - unfortunately it is not possible. The only option is to deal with AVAudioSession.availableInputs to get a list of inputs, build and UIAlertController with it and using combination of setPreferredInput and overrideOutputAudioPort set the user's choice.

gwyhyr
  • 51
  • 6