0

i am working on a iOS application with accessibility support. At some point in my application flow, i present an alert view. After presenting the view, i want to focus on the view using UIAccessibilityPostNotification, however the notification seems to get overridden.

[alertView show];
UIAccessibilityPostNotification(UIAccessibilityScreenChangedNotification,alertView.somesubView);

However i do not see the effect of this notification. The accessibility focus goes to some other view object in the background.

However, when i use dispatch_after with 0 delay, it works

[alertView show];
dispatch_time_t delay = dispatch_time(DISPATCH_TIME_NOW,0 * NSEC_PER_SEC);
dispatch_after(delay,dispatch_get_main_queue(), ^void(){
  UIAccessibilityPostNotification(UIAccessibilityScreenChangedNotification,alertView.somesubView);
  });

Can someone explain what is the reason ?

Justin
  • 20,509
  • 6
  • 47
  • 58
Dynamite
  • 341
  • 2
  • 5
  • 17

1 Answers1

0

You've stumbled upon the standard solution. It's likely that the user interface or accessibility hierarchies may not have updated, yet, to reflect the presence of the alert view. An async dispatch to the main queue ensures that all other enqueued tasks, including any updates to user interface or accessibility state, execute before the notification is posted.

That said, VoiceOver should focus alert views automatically. You might want to investigate what interfered with this behavior in the first place.

Justin
  • 20,509
  • 6
  • 47
  • 58