Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to receive UIAccessibilityNotifications in iPhone App

Tags:

iphone

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!

like image 643
MobileDev852 Avatar asked Jan 26 '10 02:01

MobileDev852


1 Answers

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.

like image 112
kennytm Avatar answered Oct 04 '22 05:10

kennytm