检测airplay设备是否可用

时间:2019-07-07 17:47:50

标签: ios swift airplay

我只想在有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

0 个答案:

没有答案