tags:

views:

65

answers:

1

The following is not working:

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

Together with that, on the Observer side:

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

Any clues?

N.B. My uber-goal is to get a notification when a (system-generated) UIAlertView is shown.

A: 

Self answering...

The right 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) contains a sub-view which is an instance of UIAlertView

Ariel Malka
Follow-up: it is actually not working for detecting system-generated alerts like those displayed during inApp Purchase...
Ariel Malka
Finally: UIApplicationWillResignActiveNotification proved to be the right thing to observe. It works for the first UIAlertView generated by inApp Purchase and also for the confirmation UIAlertView generated when using a UIWebView to place a phone call...
Ariel Malka