I'm interested in capturing UI changes in my application programmatically and thought that the UIAccessibility
protocol may help. I've found how to post UIAccessibilityLayoutChangedNotification
and UIAccessibilityScreenChangedNotification
but I'm not sure how to register to receive these notifications.
I've tried using NSNotificationCenter
, but the name
param expects a string
, while the two notifications above are of the type UIAccesibilityNotifications
which is an int
.
Any idea how to register for these notifications?
Thanks!
That's a great question! Unfortunately you cannot receive these "notifications" without affecting normal behavior. (i.e. "no you can't")
If you disassemble UIKit, you'll find UIAccessibilityPostNotification
is implemented like this:
static void (*__UIAccessibilityBroadcastCallback)(UIAccessibilityNotifications notification, id argument);
void UIAccessibilityPostNotification(UIAccessibilityNotifications notification, id argument) {
__UIAccessibilityBroadcastCallback (notification, argument);
}
That means these accessibility "notifications" aren't any normal notifications. Rather, they are just parameters to an internal callback function. How the callback function is implemented depends on the accessibility bundle you're using.
You can replace the callback function with your own using the undocumented API _UIAccessibilitySetBroadcastCallback
:
void _UIAccessibilitySetBroadcastCallback(void (*replacement)(UIAccessibilityNotifications notification, id argument)) {
__UIAccessibilityBroadcastCallback = replacement;
}
However, there isn't a corresponding "get" function (not even private), so once you set it, the original listeners cannot be notified again.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With