开发者

KVO on the "windows" value of UIApplication?

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 开发者_如何学Python*)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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜