I'd like to display the Airplay icon in an iPhone app as an UIBarButtonItem
only when airplay devices (other than the user's iPhone) are available.
var volumeView = MPVolumeView!
I've set up the UIBarButtonItem
in the viewDidLoad()
like that:
volumeView = MPVolumeView(frame: CGRect(x: 0.0, y: 0.0, width: 0.0, height: 0.0))
volumeView.showsVolumeSlider = false
let airplayBarButtonItem = UIBarButtonItem(customView: volumeView)
if let routeButton = volumeView.subviews.last as? UIButton,
let routeButtonTemplateImage = routeButton.currentImage?.withRenderingMode(.alwaysTemplate) {
volumeView.setRouteButtonImage(routeButtonTemplateImage, for: .normal)
volumeView.tintColor = myColor
}
volumeView.showsRouteButton = volumeView.areWirelessRoutesAvailable
In the viewWillAppear()
:
volumeView.showsRouteButton = volumeView.areWirelessRoutesAvailable
Now the app needs to update the current screen when Airplay devices become available, is there a way to do that?
EDIT: This notification seems to be deprecated, is there any replacement? https://developer.apple.com/documentation/mediaplayer/mpvolumeviewwirelessrouteactivedidchangenotification?language=objc#discussion