Search code examples
iosswiftiphonekeyboardaccessibility

accessibilityElementDidBecomeFocused only gets called with VoiceOver enabled


Background

  • I have a UICollectionViewCell, where I override accessibilityElementDidBecomeFocused method.
  • I also override canBecomeFocused to always return true.
  • The App allows Accessibility->Full Keyboard Access (allowing the user to use the app with just Keyboard). isAccessibilityElement is also set to true

Problem I have two scenarios

  1. When both Keyboard access and VoiceOver are enabled In this case accessibilityElementDidBecomeFocused gets called as expected.

  2. When both Keyboard access is enabled but VoiceOver is disabled In this case accessibilityElementDidBecomeFocused isn't getting called.


Solution

  • I asked the same question on Developer apple forums, and one of the apple engineers confirm that indeed this API only works with VoiceOver. https://developer.apple.com/forums/thread/745602?login=true&page=1#778932022

    The engineer highlighted the https://developer.apple.com/documentation/uikit/uifocussystem API for Keyboard related focus, where I found and used didUpdateNotification Notification for my usecase. This notification triggered as expected when I changed focus only using KeyboardAccess