更改控制中心(远程命令中心)中的辅助功能标签

changing the accessibility label in control center (remote command center)

我有一个简单的应用程序可以播放广播电台。我添加了一个 MPRemoteCommandCenter 让用户通过控制中心控制音频。 一切正常。

但是,我想更改他们的辅助功能标签。但这是事情无法按预期工作的部分。

我已经按如下方式设置了我的 remoteCommandCenter:

let remoteCommandCenter = MPRemoteCommandCenter.shared()

然后,我添加了控件和处理程序:

remoteCommandCenter.playCommand.isEnabled = true
remoteCommandCenter.playCommand.addTarget(self, action: #selector(ExternalPlaybackController.handleExternalPlayPauseCommandEvent(_:)))

然后,我想添加一些辅助功能标签:

remoteCommandCenter.playCommand.accessibilityLabel = "Play radio"

这是行不通的。如果我调试代码,编译器将执行该行。我做错了什么? 您甚至可以更改 remoteCommandCenter 的辅助功能标签吗?

Can you even change the accessibility labels of the remoteCommandCenter?

我从未使用过这种组件,但我认为它被 VoiceOver 忽略了,因为屏幕 reader 不将其识别为辅助功能元素。

在我看来,您的代码编译没有问题,因为您的可访问性属性属于 UIAccessibility 非正式协议,这意味着它被很好地识别为代码。
但是,它不会被 VoiceOver 解释为要读出的信息,因为您的元素不是一种 UIKit 控件。

我建议 创建一个 UIAccessibilityElement for your playCommand so as to customize its behaviour as you wish ⟹ Apple doc 状态 :

The UIAccessibility informal protocol is also implemented by the UIAccessibilityElement class, which represents custom user interface objects. If you create a completely custom UIView subclass, you might need to create an instance of UIAccessibilityElement to represent it. In this case, you would support all the UIAccessibility properties to correctly set and return the accessibility element’s properties.