我正在努力为现有 macOS 代码库中的自定义 UI 元素添加可访问性。我们有一个自定义错误窗口,它会在发生错误时出现,我正在尝试让 VoiceOver 在发生错误时宣布错误。
目前,我正在尝试使用该NSAccessibility.post(element: Any, notification: NSAccessibility.Notification, userInfo: [NSAccessibility.NotificationUserInfoKey : Any]?)
方法,但是在运行代码时,没有说出通知。
这是我目前在 NSViewController 中的内容:
NSAccessibility.post(element: self, notification: .announcementRequested, userInfo: [
.announcement: NSLocalizedString("CANT_CONNECT_ERROR", comment: "Error string for connection failure"),
.priority: NSAccessibilityPriorityLevel.high
])
Run Code Online (Sandbox Code Playgroud)
我的期望是,使用该.announcementRequested
选项,VoiceOver 应该会自动选择并说出公告,但没有运气。我尝试使用不同的通知类型,尝试在.announcement
参数中放入一个硬编码的字符串值,并尝试使用.rawValue
和90
作为.priority
参数。