KVO by UIApplication "window" value?

The following doesn't work:

[[UIApplication sharedApplication] addObserver:self forKeyPath:@"windows"
   options:(NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOld)
   context:NULL];

      

At the same time, from the side of the observer:

- (void) observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
  NSLog(@"never reached!");
}

      

Any hints?

NB My uber goal is to get notified when (system generated) UIAlertView is shown.

+2


a source to share


1 answer


Answering machine ...

The correct way to detect when an arbitrary UIAlertView is shown is to use NSNotificationCenter:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(windowDidBecomeVisible:) name:UIWindowDidBecomeVisibleNotification object:nil];

      



And then, inside:

- (void) windowDidBecomeVisible:(NSNotification*)notification {}

      

Check if the UIWindow in question (accessible via notification.object) matches the subview being an instance of UIAlertView

+3


a source







All Articles