Reputation: 31
I have a Mac application.
I want to enable / disable some app functionality depending upon if VoiceOver has been enabled or not.
I know that I can detect if VoiceOver has been enabled / disabled using [[NSWorkspace sharedWorkspace] isVoiceOverEnabled].
Apart from this, I want to register for a notification to detect the changes in VoiceOver status (enabled / disabled).
I found that, this can be achieved in iOS by registering to UIAccessibilityVoiceOverStatusDidChangeNotification notification.
But, I did not find similar notification for macOS.
Can anyone please tell me how can I achieve this in macOS.
Upvotes: 1
Views: 233
Reputation: 818
You can use KVO to observe changes to NSWorkspace.shared.isVoiceOverEnabled
I used closure based KVO in Swift and added an observation property to my class:
private var voiceOverObservation: NSKeyValueObservation?
and in init:
voiceOverObservation = NSWorkspace.shared.observe(\.isVoiceOverEnabled) { _, _ in
print(NSWorkspace.shared.isVoiceOverEnabled)
}
Upvotes: 2