Search code examples
objective-ciosaccessibilityvoiceover

VoiceOver before heavy processing in main thread


I want to accomplish following effect:

  • User presses the button;
  • VoiceOver speaks aloud a "processing" sentence;
  • Performing some heavy processing.

Everything is being ran in main thread and I don't want GUI to be able to update in that time. For that, I'd like the method not to return before the end of heavy processing. I have following code:

UIAccessibilityPostNotification(UIAccessibilityAnnouncementNotification,
    @"Processing");
heavyProcessing();

The problem is, that VoiceOver speaks the information after heavy processing has been completed.

How to make VoiceOver speak out the information "asynchronously", before method finishes and returns control to the main loop? If necessary, the heavy processing may be ran in another thread.


Solution

  • That would be because, if the main thread is doing heavy processing, it can't do anything else and that would include initiating voice over requests.

    In fact, there are many things that happen on the main thread that mean that you never want to do lengthy processing on it. Your app can't, for instance, respond to notifications from the OS like low memory warnings. If that's the case, iOS might kill your app thinking it has hung.

    What you need to do is run your heavy processing on a background thread - I recommend using NSOperationQueue - and disable the controls you don't want to work while it is happening.