Skip to content
This repository

Automatically enable accessibility on the device also #93

Merged
merged 2 commits into from over 2 years ago

2 participants

Stewart Gleadow Jim Puls
Stewart Gleadow

My previous pull request for enabling accessibility on the device. After some comments on my blog post about it, I modified the code to also run on the device. I wrote up my findings on another blog post

Without this code, when I run KIF on a device without VoiceOver on, the accessibility values are not available to KIF and the test fails. With this code, the values become available automatically and the tests can run on the device.

Jim Puls
Owner

Awesome, but I'd change the name of the method from _enableAccessibilityInSimulator to something more general.

Stewart Gleadow

Good catch, I missed that completely. I have renamed the method to be general

Jim Puls puls merged commit 87b535b into from November 15, 2011
Jim Puls puls closed this November 15, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 18 additions and 13 deletions. Show diff stats Hide diff stats

  1. 31  Classes/KIFTestController.m
31  Classes/KIFTestController.m
@@ -30,7 +30,7 @@ @interface KIFTestController ()
30 30
 @property (nonatomic, retain) NSDate *currentStepStartDate;
31 31
 @property (nonatomic, copy) KIFTestControllerCompletionBlock completionBlock;
32 32
 
33  
-+ (void)_enableAccessibilityInSimulator;
  33
++ (void)_enableAccessibility;
34 34
 
35 35
 - (void)_initializeScenariosIfNeeded;
36 36
 - (BOOL)_isAccessibilityInspectorEnabled;
@@ -68,25 +68,30 @@ @implementation KIFTestController
68 68
 
69 69
 + (void)load
70 70
 {
71  
-    [KIFTestController _enableAccessibilityInSimulator];
  71
+    [KIFTestController _enableAccessibility];
72 72
 }
73 73
 
74  
-+ (void)_enableAccessibilityInSimulator;
  74
++ (void)_enableAccessibility;
75 75
 {
76 76
     NSAutoreleasePool *autoreleasePool = [[NSAutoreleasePool alloc] init];
  77
+    NSString *appSupportLocation = @"/System/Library/PrivateFrameworks/AppSupport.framework/AppSupport";
77 78
     
78  
-    NSString *simulatorRoot = [[[NSProcessInfo processInfo] environment] objectForKey:@"IPHONE_SIMULATOR_ROOT"];
  79
+    NSDictionary *environment = [[NSProcessInfo processInfo] environment];
  80
+    NSString *simulatorRoot = [environment objectForKey:@"IPHONE_SIMULATOR_ROOT"];
79 81
     if (simulatorRoot) {
80  
-        void *appSupportLibrary = dlopen([[simulatorRoot stringByAppendingPathComponent:@"/System/Library/PrivateFrameworks/AppSupport.framework/AppSupport"] fileSystemRepresentation], RTLD_LAZY);
81  
-        CFStringRef (*copySharedResourcesPreferencesDomainForDomain)(CFStringRef domain) = dlsym(appSupportLibrary, "CPCopySharedResourcesPreferencesDomainForDomain");
  82
+        appSupportLocation = [simulatorRoot stringByAppendingString:appSupportLocation];
  83
+    }
  84
+    
  85
+    void *appSupportLibrary = dlopen([appSupportLocation fileSystemRepresentation], RTLD_LAZY);
  86
+    
  87
+    CFStringRef (*copySharedResourcesPreferencesDomainForDomain)(CFStringRef domain) = dlsym(appSupportLibrary, "CPCopySharedResourcesPreferencesDomainForDomain");
  88
+    
  89
+    if (copySharedResourcesPreferencesDomainForDomain) {
  90
+        CFStringRef accessibilityDomain = copySharedResourcesPreferencesDomainForDomain(CFSTR("com.apple.Accessibility"));
82 91
         
83  
-        if (copySharedResourcesPreferencesDomainForDomain) {
84  
-            CFStringRef accessibilityDomain = copySharedResourcesPreferencesDomainForDomain(CFSTR("com.apple.Accessibility"));
85  
-            
86  
-            if (accessibilityDomain) {
87  
-                CFPreferencesSetValue(CFSTR("ApplicationAccessibilityEnabled"), kCFBooleanTrue, accessibilityDomain, kCFPreferencesAnyUser, kCFPreferencesAnyHost);
88  
-                CFRelease(accessibilityDomain);
89  
-            }
  92
+        if (accessibilityDomain) {
  93
+            CFPreferencesSetValue(CFSTR("ApplicationAccessibilityEnabled"), kCFBooleanTrue, accessibilityDomain, kCFPreferencesAnyUser, kCFPreferencesAnyHost);
  94
+            CFRelease(accessibilityDomain);
90 95
         }
91 96
     }
92 97
     
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.