Forum Xamarin.iOS

Accessibility: need help with UIAccessibilityPostNotification binding

There are no bindings for various UIAccessibility* items. Nic Wise created a ticket some time ago regarding this: https://bugzilla.xamarin.com/show_bug.cgi?id=2360.

You can use UIResponder.SetValueForKey() to set some accessibility items programatically, but I also need UIAccessibilityPostNotification().

Has anyone created a binding for UIAccessibilityPostNotification or can someone from Xamarin help me create one?

I'm really surprised there is not more support for voice-over accessibility in MonoTouch. IMHO it is very important to support this in our apps. Nic created a great seminar on accessibility for MonoTouch and Android. His extension methods are here.

I've created some extension methods to set accessibility traits which are used to indicate things like a control is a button, link, selected, etc. I posted them to a StackOverflow question.

Posts

  • I used P/Invoke to create an interface to:

    UIKIT_EXTERN void UIAccessibilityPostNotification(UIAccessibilityNotifications notification, 
        id argument);
    

    Which might be used like so in Objective-C:

    UIAccessibilityPostNotification(UIAccessibilityAnnouncementNotification, 
        @"hello world");
    

    My simple C# code to speak text when VoiceOver is enabled:

    using System;
    using MonoTouch;
    using MonoTouch.Foundation;
    using System.Runtime.InteropServices;
    
    namespace Free.MonoTouch
    {
        public static class UIAccessibility
        {
            [DllImport(Constants.UIKitLibrary, EntryPoint="UIAccessibilityPostNotification")]
            public extern static void PostNotification(uint notification, IntPtr id);
    
            public static void PostVoiceOver(string textToSpeak)
            {
                PostNotification(1008, new NSString(textToSpeak).Handle);
            }
        }
    }
    

    I did hard code UIAccessibilityAnnouncementNotification value of 1008 which isn't good. There might be a way to extract an exported global defined in UIKit as described here:

    http://limbioliong.wordpress.com/2011/11/11/accessing-exported-data-from-a-dll-in-managed-code/

    But just creating a small Objective-C library that implements getUIAccessibilityAnnouncementNotification() et all or simply PostVoiceOver() would probably be easier. Any thoughts?

    I hope that my work is temporary and full accessibility bindings can be added ASAP. There are a lot of other neat accessibility features and some that should be implemented as events:

    • UIAccessibilityAnnouncementDidFinishNotification - posted by UIKit when the system has finished reading an announcement
    • UIAccessibilityVoiceOverStatusChanged - posted by UIKit when VoiceOver starts or stops.
Sign In or Register to comment.