2010-05-17 2 views
2

Ce qui suit ne fonctionne pas:KVO sur la valeur "windows" de UIApplication?

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

Avec qui, du côté de l'observateur:

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

Des indices?

N.B. Mon but ultime est d'obtenir une notification quand un UIAlertView (généré par le système) est affiché.

Répondre

3

auto réponse ...

La bonne façon de détecter lorsqu'un UIAlertView arbitraire est montré est d'utiliser NSNotificationCenter:

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

Et puis, à l'intérieur:

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

Vérifiez si l'UIWindow en question (accessible via notification.object) contient une sous-vue qui est une instance de UIAlertView

+0

Suivi: il est en réalité ne fonctionne pas pour détecter les alertes générées par le système comme celles affichées au cours InApp Achat ... –

+0

Enfin: UIApplicationWillResignActiveNotification avéré être la bonne chose à observer. Il fonctionne pour la première UIAlertView générée par InApp Achat et aussi pour la confirmation UIAlertView générée lors de l'utilisation d'un UIWebView pour passer un appel téléphonique ... –

Questions connexes