I want to get the name of the AirPlay or Bluetooth device my iPhone is connected to. I have somewhat achieved this with the following code...
let currentRoute = AVAudioSession.sharedInstance().currentRoute
for output in currentRoute.outputs {
print("Connected port name: \(output.portName)")
}
But, whenever my iPhone is connected to an AirPlay device such as a HomePod or Apple TV, the portName returned is just "Speaker". I would like to get the name of the HomePod or Apple TV. Whenever my device is connected to Bluetooth, though, this works. For example, whenever I am connected to my AirPods, the name "Jacob's AirPods" is returned. Whenever I am connected to another Bluetooth device, the correct name is returned.
I believe that getting the name of the AirPlay device should be possible because Apple does it in their Apple Music app and system-wide. Like bellow...
Any suggestions?