iOS 13: How to detect "Voice Control" is running
Asked Answered
S

3

6

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).

Szeged answered 3/9, 2019 at 21:53 Comment(0)
L
2

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)

Lodhia answered 4/9, 2019 at 7:28 Comment(0)
S
0

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
  }
}
Szeged answered 22/10, 2019 at 23:19 Comment(3)
using 'accessibilityActivate()' is great but I don't understand how you can detect that the VoiceControl feature is running and not something else?Lodhia
@Lodhia I added a check to detect if it's most likely Voice control or Full Keyboard Access. Again, since there is no API to support this yet it's just a best guess.Szeged
@Lodhia I have checked your above code. This is not working.Ironsides
C
0

This should work

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

@objc private func voiceOverStatusDidChange() {
    if UIAccessibility.isVoiceOverRunning {
      // do something
    }
}
Clementeclementi answered 22/9, 2023 at 5:52 Comment(1)
Hey Prabhakar, the question is for Voice Control not Voice OverSzeged

© 2022 - 2024 — McMap. All rights reserved.