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 {
UIAccessibilityPostNotification(UIAccessibilityAnnouncementNotification,
@"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.