Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UIApplication: AccessibilityLanguage API appears to be missing #21925

Closed
Felix-Dev opened this issue Jan 8, 2025 · 2 comments · Fixed by #21943
Closed

UIApplication: AccessibilityLanguage API appears to be missing #21925

Felix-Dev opened this issue Jan 8, 2025 · 2 comments · Fixed by #21943

Comments

@Felix-Dev
Copy link

Felix-Dev commented Jan 8, 2025

Apple platform

iOS

Framework version

net8.0-*

Affected platform version

.NET 8.0.303

Description

We are currently working on adding accessibility to our app and support for Apple VoiceOver. The display language of our app might differ from the user's system language. For example, the user might have configured their iPhone to display system UI in English, however, our app UI content in German. We've noticed that in this case VoiceOver pronounces our German labels as if they represent English words which is expected behavior:

If you don't set a language, the system uses the user’s current language setting.

(https://developer.apple.com/documentation/objectivec/nsobject/1615192-accessibilitylanguage?language=objc#discussion)

It is possible to configure the language used when speaking the label/accessibility description/etc... using the API

accessibilityLanguage

(https://developer.apple.com/documentation/objectivec/nsobject/1615192-accessibilitylanguage?language=objc)
While this property can bet set on every UIView it looks like it is also possible to set it globally using the UIApplication instance:

application.accessibilityLanguage = @"de";

(https://stackoverflow.com/questions/21283862/uiaccessibility-default-language-throughout-the-app)

I have tried to do the same in a MAUI app but I did not find such a property:
image

It looks like the API is missing from the Xamari iOS bindings? One thing I noticed is that for .NET for iOS, the AccessibilityLanguage API is defined first for an UIView:
https://learn.microsoft.com/en-us/dotnet/api/uikit.uiview.accessibilitylanguage?view=xamarin-ios-sdk-12
Whereas in UIKit, that API is defined for a NSObject. UIApplication is a NSObject but not a UIView which technically explains why that property is missing here.

Steps to Reproduce

n/a

Did you find any workaround?

No feasible workaround yet.

Relevant log output

No response

@rolfbjarne
Copy link
Member

Looks like our UIApplication bindings are missing conformance to the UIAccessibility protocol.

I'll have a look.

As a workaround, something like this should work:

using System.Runtime.InteropServices;
using CoreFoundation;
using Foundation;
using ObjCRuntime;

public static class UIAppearanceExtensions {
	public static void SetAccessibilityLanguage (this NSObject object, string language)
	{
		var languageHandle = CFString.CreateNative (language);
		objc_msgSend (object.GetHandle (), Selector.GetHandle ("setAccessibilityLanguage:"), languageHandle);
		CFString.ReleaseNative (languageHandle);
	}

	[DllImport (Constants.ObjectiveCLibrary)]
	static extern void objc_msgSend (IntPtr handle, IntPtr selector, IntPtr arg0);
}

and then you can use it like this:

application.SetAccessibilityLanguage ("de");

@rolfbjarne rolfbjarne added this to the Future milestone Jan 10, 2025
rolfbjarne added a commit that referenced this issue Jan 10, 2025
UIAccessibility is a category on NSObject, with a comment saying
"UIAccessibility is implemented on all standard UIKit views and controls".

We can't create a single binding that exposes UIAccessibility as that comment
states, and adding it to NSObject will create a lot of noise for all other
types.

So a long time ago we decided to only add UIAccessibility to a few UIKit types
(UIView, UIBarItem and UIImage), but it seems UIApplication should have it
too, so do that.

Fixes #21925.
@Felix-Dev
Copy link
Author

@rolfbjarne Thanks for the quick workaround (I can confirm it works) and fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants