Search code examples
iosswiftuiaccessibility

Determine if an assistive technology is enabled in SwiftUI (like voice over)


I wonder if there's a way to determine if any assistive technology like voice over is enabled in SwiftUI? I found out one answer here where I can specifically choose an assistive technology like UIAccessibility.isVoiceOverRunning. But I wonder if there's a more "SwiftUI"-way to do it?


Solution

  • A more SwiftUI-way to determine if any assistive technology is enabled is by using the @Environment() property wrapper and choose whatever assistive technology you liked.

    Example:

    // Determines if any assistive technology is active
    @Environment(\.accessibilityEnabled) private var accessibilityEnabled
    
    // Determines if voice over is enabled
    @Environment(\.accessibilityVoiceOverEnabled) private var voiceOverEnabled
    
    // Determines if reduce motion is enabled
    @Environment(\.accessibilityReduceMotion) private var reduceMotionEnabled