@@ -202,6 +202,51 @@ - (BOOL)didActivateAccessibilityCustomAction:(UIAccessibilityCustomAction *)acti
202
202
203
203
- (NSString *)accessibilityValue
204
204
{
205
+ static dispatch_once_t onceToken;
206
+ static NSDictionary <NSString *, NSString *> *rolesAndStatesDescription = nil ;
207
+
208
+ dispatch_once (&onceToken, ^{
209
+ NSString *bundlePath = [[NSBundle mainBundle ]pathForResource:@" AccessibilityResources" ofType: @" bundle" ];
210
+ NSBundle *bundle = [NSBundle bundleWithPath: bundlePath];
211
+
212
+ if (bundle) {
213
+ NSURL *url = [bundle URLForResource: @" Localizable" withExtension: @" strings" ];
214
+ if (@available (iOS 11.0 , *)) {
215
+ rolesAndStatesDescription = [NSDictionary dictionaryWithContentsOfURL: url error: nil ];
216
+ } else {
217
+ // Fallback on earlier versions
218
+ rolesAndStatesDescription = [NSDictionary dictionaryWithContentsOfURL: url];
219
+ }
220
+ }
221
+ if (rolesAndStatesDescription == nil ) {
222
+ NSLog (@" Cannot load localized accessibility strings." );
223
+ rolesAndStatesDescription = @{
224
+ @" alert" : @" alert" ,
225
+ @" checkbox" : @" checkbox" ,
226
+ @" combobox" : @" combo box" ,
227
+ @" menu" : @" menu" ,
228
+ @" menubar" : @" menu bar" ,
229
+ @" menuitem" : @" menu item" ,
230
+ @" progressbar" : @" progress bar" ,
231
+ @" radio" : @" radio button" ,
232
+ @" radiogroup" : @" radio group" ,
233
+ @" scrollbar" : @" scroll bar" ,
234
+ @" spinbutton" : @" spin button" ,
235
+ @" switch" : @" switch" ,
236
+ @" tab" : @" tab" ,
237
+ @" tablist" : @" tab list" ,
238
+ @" timer" : @" timer" ,
239
+ @" toolbar" : @" tool bar" ,
240
+ @" checked" : @" checked" ,
241
+ @" unchecked" : @" not checked" ,
242
+ @" busy" : @" busy" ,
243
+ @" expanded" : @" expanded" ,
244
+ @" collapsed" : @" collapsed" ,
245
+ @" mixed" : @" mixed" ,
246
+ };
247
+ }
248
+ });
249
+
205
250
if ((self.accessibilityTraits & SwitchAccessibilityTrait) == SwitchAccessibilityTrait) {
206
251
for (NSString *state in self.accessibilityState ) {
207
252
id val = self.accessibilityState [state];
@@ -214,41 +259,7 @@ - (NSString *)accessibilityValue
214
259
}
215
260
}
216
261
NSMutableArray *valueComponents = [NSMutableArray new ];
217
- static NSDictionary <NSString *, NSString *> *roleDescriptions = nil ;
218
- static dispatch_once_t onceToken1;
219
- dispatch_once (&onceToken1, ^{
220
- roleDescriptions = @{
221
- @" alert" : @" alert" ,
222
- @" checkbox" : @" checkbox" ,
223
- @" combobox" : @" combo box" ,
224
- @" menu" : @" menu" ,
225
- @" menubar" : @" menu bar" ,
226
- @" menuitem" : @" menu item" ,
227
- @" progressbar" : @" progress bar" ,
228
- @" radio" : @" radio button" ,
229
- @" radiogroup" : @" radio group" ,
230
- @" scrollbar" : @" scroll bar" ,
231
- @" spinbutton" : @" spin button" ,
232
- @" switch" : @" switch" ,
233
- @" tab" : @" tab" ,
234
- @" tablist" : @" tab list" ,
235
- @" timer" : @" timer" ,
236
- @" toolbar" : @" tool bar" ,
237
- };
238
- });
239
- static NSDictionary <NSString *, NSString *> *stateDescriptions = nil ;
240
- static dispatch_once_t onceToken2;
241
- dispatch_once (&onceToken2, ^{
242
- stateDescriptions = @{
243
- @" checked" : @" checked" ,
244
- @" unchecked" : @" not checked" ,
245
- @" busy" : @" busy" ,
246
- @" expanded" : @" expanded" ,
247
- @" collapsed" : @" collapsed" ,
248
- @" mixed" : @" mixed" ,
249
- };
250
- });
251
- NSString *roleDescription = self.accessibilityRole ? roleDescriptions[self .accessibilityRole]: nil ;
262
+ NSString *roleDescription = self.accessibilityRole ? rolesAndStatesDescription[self .accessibilityRole]: nil ;
252
263
if (roleDescription) {
253
264
[valueComponents addObject: roleDescription];
254
265
}
@@ -259,16 +270,16 @@ - (NSString *)accessibilityValue
259
270
}
260
271
if ([state isEqualToString: @" checked" ]) {
261
272
if ([val isKindOfClass: [NSNumber class ]]) {
262
- [valueComponents addObject: stateDescriptions [[val boolValue ] ? @" checked" : @" unchecked" ]];
273
+ [valueComponents addObject: rolesAndStatesDescription [[val boolValue ] ? @" checked" : @" unchecked" ]];
263
274
} else if ([val isKindOfClass: [NSString class ]] && [val isEqualToString: @" mixed" ]) {
264
- [valueComponents addObject: stateDescriptions [@" mixed" ]];
275
+ [valueComponents addObject: rolesAndStatesDescription [@" mixed" ]];
265
276
}
266
277
}
267
278
if ([state isEqualToString: @" expanded" ] && [val isKindOfClass: [NSNumber class ]]) {
268
- [valueComponents addObject: stateDescriptions [[val boolValue ] ? @" expanded" : @" collapsed" ]];
279
+ [valueComponents addObject: rolesAndStatesDescription [[val boolValue ] ? @" expanded" : @" collapsed" ]];
269
280
}
270
281
if ([state isEqualToString: @" busy" ] && [val isKindOfClass: [NSNumber class ]] && [val boolValue ]) {
271
- [valueComponents addObject: stateDescriptions [@" busy" ]];
282
+ [valueComponents addObject: rolesAndStatesDescription [@" busy" ]];
272
283
}
273
284
}
274
285
0 commit comments