Ke MA Ke MA - 1 year ago 162
iOS Question


I'm pretty new to iOS Accessibility area and I'm trying to use this UIAccessibilityNotification feature but it is not working as I thought it would. I write a pretty simple app with just one button and when you click the button, this method is called.

- (IBAction)announce:(id)sender {
@"Speak this out loud");

In my understanding, when you click the button, the voiceover will read "Speak this out loud", but it is reading the button name instead. Could anyone tell my whats wrong with the code or why am I using it wrong?

And to make it clear I double tapped the button. When you single tap the button it reads the button name and trait("button"), and when you double tap it it will just read button name.

Thanks to @ChrisCM 's answer. Put a delay to the announcement makes it work.

@IBAction func announce(sender: AnyObject) {
let dispatchTime: dispatch_time_t = dispatch_time(DISPATCH_TIME_NOW, Int64(2 * Double(NSEC_PER_SEC)))

dispatch_after(dispatchTime, dispatch_get_main_queue(), {
UIAccessibilityPostNotification(UIAccessibilityAnnouncementNotification, "Item added to cart")

But here is still a little problem that after click the "Add to cart" button, the voiceover will target the first accessible item which is the back button and read "back button" then read the announcementNotification argument.

Answer Source

Your understanding of how the notification works is correct, however your understanding of how voiceover handles basic interaction is not. When you post your announcement it starts, but it's immediately interrupted by the standard voiceover response to ui interaction, which is to announce the accessibility label of what was pressed. Post your announcement after some sufficient delay or based on basically anything but a click.

For the second part of your issue (the first accessibility issue being focused). This is likely because of some screen re-drawing that is occuring, so an inherent UIAccessibilityScreenChangedNotification is being posted by the View drawing heirarchy. You should override this, by posting this notification yourself, with the element you prefer to have highlighted. Probably either the element that initiated the screen change OR the new content that was added as a result of this interaction.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download