我只想在有airplay设备(用户的iPhone除外)时在iPhone应用程序中将Airplay图标显示为UIBarButtonItem
。
var volumeView = MPVolumeView!
我已经在UIBarButtonItem
中设置了viewDidLoad()
:
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
在viewWillAppear()
中:
volumeView.showsRouteButton = volumeView.areWirelessRoutesAvailable
现在,当Airplay设备可用时,应用程序需要更新当前屏幕,有办法吗?
编辑:此通知似乎已弃用,是否有替代品? https://developer.apple.com/documentation/mediaplayer/mpvolumeviewwirelessrouteactivedidchangenotification?language=objc#discussion