开发者

KVO on the "windows" value of UIApplication?

开发者 https://www.devze.com 2022-12-31 01:52 出处:网络
The following is not working: [[UIApplication sharedApplication] addObserver:self forKeyPath:@\"windows\"

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

精彩评论

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