1

How to implement to get UIAccessibilityVoiceOverStatusChanged Notification?

I tried like below but nothing happens :

NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
[nc addObserver:self selector:@selector(notified:) name:UIAccessibilityVoiceOverStatusChanged object:self];
Mutix
  • 4,196
  • 1
  • 27
  • 39
user580045
  • 11
  • 3

3 Answers3

0

I think you might try adding the observer in the awakeFromNib method with the right selector signature.

Something like this will work

- (void)awakeFromNib {
    [super awakeFromNib];
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(voiceOverChanged)
                                                 name:UIAccessibilityVoiceOverStatusChanged
                                               object:nil];
    [self voiceOverChanged];
}

- (void)dealloc {
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIAccessibilityVoiceOverStatusChanged object:nil];
}

- (void)voiceOverChanged {
// Your actions here
}
Jesús Hurtado
  • 295
  • 2
  • 12
0

you can get the UIAccessibilityVoiceOverStatusChanged Notification with the code

- (void)viewDidLoad {
        [super viewDidLoad];
        [[NSNotificationCenter defaultCenter]
            addObserver:self
            selector:@selector(didChangeVoiceOverStatus:)
            name:UIAccessibilityVoiceOverStatusChanged
            object:nil];
    }

- (void)didChangeVoiceOverStatus:(NSNotification *)notification {
        if (UIAccessibilityIsVoiceOverRunning()) {
            NSLog(@"VoiceOver is ON.");
        } else {
            NSLog(@"VoiceOver is OFF.");
        }
    }
0x0
  • 43
  • 6
  • 2
    Better to provide at least *some* explanation of the code. Code-only and link-only answers are not recommended at this site. – clearlight Jan 04 '17 at 04:30
0

That looks reasonable, except maybe object:self should be object:nil? The other thing is to be sure your signature is correct:

- (void)voiceOverStatusChanged: (NSNotification *)notification;
Kaolin Fire
  • 2,521
  • 28
  • 43