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
}
}