User92 postedI 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.