Unified accessibility API for iOS, macOS, tvOS & watchOS.
Here are the most important changes:
Have you ever thought about improving accessibility within your apps to gain your user base instead of spending a lot of time implementing features no-one really ever asked for? Most of us did, however there has never been an easy way to tell if anyone benefits from that. What if there was a simple way to figure out if thereβs a real need to support accessibility right now. Or even better, which disability exists most across your user base.
While Appleβs accessibility API are different across all platforms and might be located in a variety of system frameworks,
Capable offers a unified and centralized API to get the current status of accessibility settings. This info can be sent to your analytics backend to learn, if people with specific handicaps are blocked from doing certain actions within your app. Furthermore, this data will help you to prioritize accessibility work.
Once youβve figured out that users with specific handicaps get stuck at a certain stage, you can make use of various Capable APIs to enable/disable accessibility support based on the userβs accessibility settings.
Capable offers a whole lot of features along with a bunch of configurations. To find more about how to use them inside the documentation section.
There are currently three different ways to integrate Capable into your apps.
use_frameworks!
target 'MyApp' do
pod 'Capable'
end
github "chrs1885/Capable"
dependencies: [
.package(url: "https://github.com/chrs1885/Capable.git", from: "2.0.1")
]
Firstly, you need to import the Capable framework in your class by adding the following import statement:
import Capable
There are two different ways to initialize the framework instance. You can either set it up to consider all accessibility features
let capable = Capable()
or by passing in only specific feature names
let capable = Capable(withFeatures: [.largerText, .boldText, .shakeToUndo])
You can find a list of all accessibility features available on each platform in the accessibility feature overview section.
If you are interested in a specific accessibility feature, you can retrieve its current status as follows:
let capable = Capable()
let isVoiceOverEnabled: Bool = capable.isFeatureEnable(feature: .voiceOver)
To get a dictionary of all features, that the Capable
instance has been initialized with you can use:
let capable = Capable()
let statusMap = capable.statusMap
This will return each feature name (key) along with its current value as described in the accessibility feature overview section.
The statusMap
object is compatible with most analytic SDK APIs. Hereβs a quick example of how to send your data along with user properties or custom events.
func sendMetrics() {
let statusMap = self.capable.statusMap
let eventName = "Capable features received"
// App Center
MSAnalytics.trackEvent(eventName, withProperties: statusMap)
// Firebase
Analytics.logEvent(eventName, parameters: statusMap)
// Fabric
Answers.logCustomEvent(withName: eventName, customAttributes: statusMap)
}
After initialization, notifications for all features that have been registered can be retrieved. To react to changes, you need to add your class as an observer as follows:
NotificationCenter.default.addObserver(
self,
selector: #selector(self.featureStatusChanged),
name: .CapableFeatureStatusDidChange,
object: nil)
Inside your featureStatusChanged
you can parse the specific feature and value:
@objc private func featureStatusChanged(notification: NSNotification) {
if let featureStatus = notification.object as? FeatureStatus {
let feature = featureStatus.feature
let currentValue = featureStatus.statusString
}
}
The following table contains all features that are available:
β API provided by Apple and fully supported by Capable
βοΈ API provided by Apple (status only, no notification) and fully supported by Capable
β API provided by Apple but not supported by Capable due to missing system settings entry.
iOS | macOS | tvOS | watchOS | |
---|---|---|---|---|
.assistiveTouch | β | β | ||
.boldText | β | β | βοΈ | |
.buttonShapes | β (iOS14) | β | ||
.closedCaptioning | β | β | ||
.darkerSystemColors | β | β | ||
.differentiateWithoutColor | β (iOS13) | β | β | |
.fullKeyboardAccess | βοΈ | |||
.grayscale | β | β | ||
.guidedAccess | β | β | ||
.hearingDevice | β | |||
.increaseContrast | β | |||
.invertColors | β | β | β | |
.largerText | β | β | βοΈ | |
.monoAudio | β | β | ||
.onOffSwitchLabels | β (iOS13) | β | ||
.prefersCrossFadeTransitions | β (iOS14) | β | ||
.reduceMotion | β | β | β | β |
.reduceTransparency | β | β | β | |
.shakeToUndo | β | β | ||
.speakScreen | β | β | ||
.speakSelection | β | β | ||
.switchControl | β | β | β | |
.videoAutoplay | β (iOS13) | β (iOS13) | ||
.voiceOver | β | β | β | β |
While most features can only have a statusMap
value set to enabled or disabled, the .largerText
and .hearingDevice
feature do offer specific values:
The Capable framework provides a logging mechanism that lets you keep track of whatβs going on under the hood. Youβll get information regarding your current setup, warnings about anything that might cause issues further on, and errors that will lead to misbehavior.
By default, all messages will be logged automatically by using Appleβs Unified Logging System. However, it also integrates with your specific logging environment by providing a custom closure that will be called instead. For example, you may want to send all errors coming from the Capable framework to your analytics service:
// Send error messages to your data backend
Capable.onLog = { message, logType in
if logType == OSLogType.error {
sendLog("Capable Framework: \(message)")
}
}
Furthermore, you can specify the minimum log level that should be considered when logging messages:
// Configure logger to only log warnings and errors (.default, .error, and .fault)
Capable.minLogType = OSLogType.default
Hereβs a list of the supported log types, their order, and what kind of messages they are used for:
OSLogType | Usage |
---|---|
.debug | Verbose logging * |
.info | Information regarding the framework setup and status changes |
.default | Warnings that may lead to unwanted behavior |
.error | Errors caused by the framework |
.fault | Errors caused by the framework due to system issues * |
* Currently not being used by the framework when logging messages.
Weβd love to see you contributing to this project by proposing or adding features, reporting bugs, or spreading the word. Please have a quick look at our contribution guidelines.
Capable is available under the MIT license. See the LICENSE file for more info.