iosswiftvoiceoveruiaccessibilitympremotecommandcenter

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


I've got a simple app that plays a radiostation. I've added a MPRemoteCommandCenter to let the user control the audio via the control center. Thats all working fine.

However, I want to change their accessibility labels. But this is the part where things don't work as expected.

I've set up my remoteCommandCenter as follows:

let remoteCommandCenter = MPRemoteCommandCenter.shared()

Then, I added controls and handlers:

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

And then, I want to add some accessibility label:

remoteCommandCenter.playCommand.accessibilityLabel = "Play radio"

This is were things don't work. If I debug the code, the compiler will execute that line. What am I making wrong? Can you even change the accessibility labels of the remoteCommandCenter?


Solution

  • Can you even change the accessibility labels of the remoteCommandCenter?

    I never worked with this kind of component but I think that it is ignored by VoiceOver because the screen reader doesn't recognize it as an accessibility element.

    In my view, your code compiles with no problems because your accessibility properties belong to the UIAccessibility informal protocol which means that it's well recognized as code.
    However, it's not interpreted by VoiceOver as information to be read out because your element isn't a kind of a UIKit control.

    I suggest to create an UIAccessibilityElement for your playCommand so as to customize its behaviour as you wish ⟹ Apple doc states :

    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.