Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

accessibilityLabel and accessibilityHint properties aren't always loaded from NIB

The UI of my iPhone application has lots of static labels, and I have set accessibility hints for them in Interface Builder. I want to access these programmatically so I can provide help bubbles - a custom subclass of UILabel recognises a touch and displays a bubble with the value of [self accessibilityHint].

However, [self accessibilityHint] returns nil. If I set the value programmatically [self setAccessibilityHint: @"Hello"] then I can access that value from my program, but the initial value from the NIB isn't available.

If I turn on the Accessibility Inspector before launching my application, the hints from the NIB files are available via the accessibilityHint property. Is there some flag somewhere that determines whether the system loads these properties; and if there is, is there some way I can set it?

My backup option is to have my controllers keep references to each UI label and set the accessibilityHint in code, but that's pretty ugly and cumbersome.

like image 570
Sam McCall Avatar asked Sep 07 '09 08:09

Sam McCall


1 Answers

Hmm, if I open Library/Preferences/com.apple.Accessibility.plist and change ApplicationAccessibilityEnabled from false to true, then it works. (That path being in ~/Library/Application Support/iPhone Simulator/)

I tried adding this at the start of main():

CFPreferencesSetAppValue(@"AccessibilityEnabled", kCFBooleanTrue, @"com.apple.Accessibility");
CFPreferencesSetAppValue(@"ApplicationAccessibilityEnabled", kCFBooleanTrue, @"com.apple.Accessibility");
CFPreferencesAppSynchronize(@"com.apple.Accessibility");

but it didn't work. (It wrote a file to Applications/{UUID}/Library/Preferences/com.apple.Accessibility.plist)

EDIT: After stepping through the UIKit code, the call that determines whether accessibility is turned on or off is

CFPreferencesGetBooleanValue(@"ApplicationAccessibilityEnabled", @"/Users/sam/Library/Application Support/iPhone Simulator/User/Library/Preferences/com.apple.Accessibility", NULL);

Note the bizarre app key, I'm not yet sure where this value comes from (my knowledge of 386 assembly is very weak!) but I can pass this key to CFPreferencesSetAppValue and it works, at least on the simulator (I don't have access to an actual device at the moment).

Also this will turn on app accessibility for all applications (since it writes it to the global plist). I can set a flag from main() if the value should be set back to false once the application has launched.

like image 96
Sam McCall Avatar answered Oct 18 '22 04:10

Sam McCall