An accessibility announcement queue for iOS with timeout and retry behavior. Built using RAC.
Swift Objective-C
Switch branches/tags
Nothing to show
Clone or download
spanage Merge pull request #9 from NachoSoto/update-ras
Update ReactiveSwift to 3.0
Latest commit 1a1951c Dec 21, 2017

README.md

AccessibilityAnnouncer

An accessibility announcement queue for iOS with timeout and retry behavior. Built using RAC.

Carthage compatible License: MIT

The Idea

Commonly when writing accessible iOS code, we write something like UIAccessibilityPostNotification(UIAccessibilityAnnouncementNotification, "Hello"). While this can work if the app is currently silent, it is very easy for these announcements to get swallowed by other announcements and/or VO reading something else that has been selected on the screen. To help tackle this problem, I've implemented an announcement queueing sytem to be used instead of the raw UIAccessibilityPostNotification function. This system allows the client to set a default timeout. If an announcement fails on first attempt, the queue will continue to retry until the timeout, at which point it will move on to the next announcement.

Note, while this does mean that app announcements interrupted by system announcements will be retried, system announcements will not be in your app queue. Thus, they will not obey the queue ordering.

Note: As of iOS 11, UIAccessibilitySpeechAttributeQueueAnnouncement should allow you to customize the prioritization of your announcement. However, if you're supporting pre-iOS 11, this attribute will not be available.

How to use

There should be one AccessibilityAnnouncer app wide. It can be initialized with a default timeout. You'll notice the default is 3 seconds, which I recommend. Passing a timeout of 0 will result in no retry behavior.

private let announcer = AccessibilityAnnouncer(defaultTimeout: 2.0)
// or
private let announcer = AccessibilityAnnouncer() // default timeout is 3 seconds

To use the announcer, simply pass it the string you'd like to announce using the announce(announcement: String) function.

announcer.announce("Hello!")

If you would like a given announcement to have a different timeout than your default (for example, you don't want it to be re-tried if it fails), you can pass a timeout argument.

announcer.announce("Hello!", withRetryTimeout: 0.0)

Installing

The easiest way to install this is with Carthage. Simply add github "spanage/AccessibilityAnnouncer" to your Cartfile.