The accessibilityLabel and accessibilityHint properties are not always loaded from the NIB

There are many static shortcuts in the user interface of my iPhone application, and I set accessibility tips for them in Interface Builder. I want to access these tools so that I can provide hints - the UILabel custom subclass recognizes the touch and displays a bubble with the value [self accessibilityHint].

However, [self accessibilityHint] returns nil. If I set the value programmatically [self setAccessibilityHint: @ "Hello"], then I can access this value from my program, but the original value from NIB is not available.

If I enable accessibility inspectors before launching the application, tooltips from NIB files are accessible through the accessibilityHint property. Is there any flag somewhere that determines if the system is loading these properties; and if there is, is there a way I can install?

My backup is to have my controllers keep links to every UI shortcut and set accessibility in the code, but this is pretty ugly and cumbersome.

+6
accessibility iphone
source share
2 answers

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

I tried adding this to the beginning of main ():

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

but it didn’t work. (He wrote a file for applications /{UUID►/Library/Preferences/com.apple.Accessibility.plist)

EDIT: after passing the UIKit code, a call that determines whether the accessibility function is enabled,

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

Pay attention to the fancy application key, I'm still not sure where this value comes from (my knowledge of assembly 386 is very weak!), But I can pass this key to CFPreferencesSetAppValue, and it works, at least on the simulator (I do not have access to the actual device at the moment).

It will also add application accessibility to all applications (since it writes it to the global plist). I can set the flag from main () if, after starting the application, the value should be returned false.

+3
source share

It works on simulator and device. Taken from http://sgleadow.github.com/blog/2011/11/16/enabling-accessibility-programatically-on-ios-devices/

 #import <dlfcn.h> NSAutoreleasePool *autoreleasePool = [[NSAutoreleasePool alloc] init]; NSString *appSupportLocation = @"/System/Library/PrivateFrameworks/AppSupport.framework/AppSupport"; NSDictionary *environment = [[NSProcessInfo processInfo] environment]; NSString *simulatorRoot = [environment objectForKey:@"IPHONE_SIMULATOR_ROOT"]; if (simulatorRoot) { appSupportLocation = [simulatorRoot stringByAppendingString:appSupportLocation]; } void *appSupportLibrary = dlopen([appSupportLocation fileSystemRepresentation], RTLD_LAZY); CFStringRef (*copySharedResourcesPreferencesDomainForDomain)(CFStringRef domain) = dlsym(appSupportLibrary, "CPCopySharedResourcesPreferencesDomainForDomain"); if (copySharedResourcesPreferencesDomainForDomain) { CFStringRef accessibilityDomain = copySharedResourcesPreferencesDomainForDomain(CFSTR("com.apple.Accessibility")); if (accessibilityDomain) { CFPreferencesSetValue(CFSTR("ApplicationAccessibilityEnabled"), kCFBooleanTrue, accessibilityDomain, kCFPreferencesAnyUser, kCFPreferencesAnyHost); CFRelease(accessibilityDomain); } } [autoreleasePool drain]; 
0
source share

All Articles