Marcin Kapusta
Marcin Kapusta

Reputation: 5396

UIButton voice assistance on demand with VoiceOver enabled

I would like to ask how to design voice over assistance on demand with VoiceOver enabled.

I have such code to create UIButton:

_myLocationButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[_myLocationButton setImage:[UIImage imageNamed:@"my_location_icon"] forState:UIControlStateNormal];
_myLocationButton.accessibilityLabel = @"My location";
_myLocationButton.accessibilityHint = @"Double tap to hear where You are, in which zone or near zone and floor information in building";
[_myLocationButton addTarget:self
                      action:@selector(myLocationButtonPressed)
            forControlEvents:UIControlEventTouchUpInside];

Now in myLocationButtonPressed method I have such code:

UIAccessibilityPostNotification(UIAccessibilityAnnouncementNotification, positionDescription);

My question is. When I'm trying to double tap when myLocationButton is active the VoiceOver is saying only: "My location". What I would like is after double tapping I'd like to hear positionDescription not button accessibilityLabel. I know that method myLocationButtonPressed is invoking but from unknown reason posting UIAccessibilityAnnouncementNotification event do nothing and I can't hear anything.

Can somebody give me some advice how to approach this kind of problem.

Upvotes: 2

Views: 1554

Answers (1)

MobA11y
MobA11y

Reputation: 18900

The only way I've found to get announcements to read out consistently, is to post the notification with a delay. This function should help.

- (void)postVoiceOverAnnouncement:(NSString*)message withDelay:(int)seconds {
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(seconds * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        UIAccessibilityPostNotification(UIAccessibilityAnnouncementNotification, @"This will get read out");
    });
}

Even with adding the starts media session trait, something is still interrupting the announcement. What you have to watch out for, is the length of your delay. If someone continues to swipe through your app, they could interrupt the announcement. Though, since in a properly accessible application, this information should be available elsewhere, they should be able to find it again. This is of course just a helpful announcement, so as not to shift focus around on unsuspecting VoiceOver users :).

Another problem with your code I noticed:

_myLocationButton.accessibilityHint = @"Double tap to hear where You are, in which zone or near zone and floor information in building";

First off, bravo for including such detailed hints! However, you should not include the "Double tap to...." portion. Users know how to interact with buttons through VoiceOver. Is this the only way to interact with this? Or might one also hit enter on an external keyboard? What about some other hypothetical AT in which the selection gesture is some other interaction... How useful is this hint for someone using a Braille Board??? Just inform the users of the consequence of interacting with the object, let the AT take care of the rest.

Upvotes: 1

Related Questions