首页 > 解决方案 > MPVolumeView 中的 showRouteButton 已弃用

问题描述

从 iOS 13 开始,MPVolumeView 中的 showRouteButton 已被弃用

let vv = MPVolumeView()
vv.showsRouteButton = false

警告是:

'showsRouteButton' was deprecated in iOS 13.0: Use AVRoutePickerView instead.

Apple 告诉我使用 AVRoutePickerView 进行路由,这没有任何意义,因为在我的情况下,我不想使用任何路由的东西,我只想隐藏它。似乎没有更多不推荐使用的方法来做到这一点。

如果它已被弃用,它应该默认隐藏,否则苹果应该允许我们隐藏它......

我可以说这是苹果 API 错误吗?

标签: iosdeprecatedmpvolumeview

解决方案


现在只是为了删除警告和默认路由按钮,我在初始化MPVolumeView.

    if volumeView.value(forKey: #keyPath(MPVolumeView.showsRouteButton)) as? Bool == true {
        volumeView.setValue(false, forKey: #keyPath(MPVolumeView.showsRouteButton))
    }

我通过键值路径检查值是否showsRouteButtontrue并将其设置false为。


推荐阅读