iOS 13: How to detect "Voice Control" is running

2.4k views Asked by At

Is there an API similar to UIAccessibility.isVoiceOverRunning to detect whether or not Voice Control is running in iOS 13? I am unable to find anything for this in the current beta docs.

Voice Control: https://www.apple.com/ios/ios-13-preview/features/ (see Accessibility section).

3

There are 3 answers

3
nickromano On

Here is a workaround when you need to show different UI when the user is in Voice Control.

Since there is no API like UIAccessibility.isVoiceOverRunning for Voice Control you'll need to override accessibilityActivate to know when the user is interacting with your app using an accessibility feature.

class Button: UIButton {

  override init(frame: CGRect) {
    super.init(frame: frame)

    addTarget(self, action: #selector(handleTouchUpInside), for: .touchUpInside)
  }

  override func accessibilityActivate() -> Bool {
    // Launch more accessible UI
    if UIAccessibility.isVoiceOverRunning {
      // VoiceOver
    } else if UIAccessibility.isSwitchControlRunning {
      // Switch Control
    } else {
      // Probably used Voice Control or Full Keyboard Access
    }
    return true
  }

  @objc func handleTouchUpInside() {
    // Standard interaction - continue to show default UI
  }
}
0
XLE_22 On

Nothing is highlighted about this amazing new feature but its 'accessibilityUserInputLabels' property: neither event name nor notification unfortunately.

Wait for the official release of iOS 13 that may provide some news in the final documentation: light a candle as I do. ;o)

2
Prabhakar Kasi On

This should work

observe(UIAccessibility.voiceOverStatusDidChangeNotification, selector: #selector(voiceOverStatusDidChange))

@objc private func voiceOverStatusDidChange() {
    if UIAccessibility.isVoiceOverRunning {
      // do something
    }
}