2009-12-14 7 views

Répondre

4

Vous pouvez simplement utiliser une minuterie et annuler votre demande de notification si elle n'est pas reçue d'ici là?

par exemple. Prenons l'exemple d'accessibilité d'Apple:

- (void) startNotifier 
{ 
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onReachabilityChanged:) name:@"kNetworkReachabilityChangedNotification" object:nil]; 
    notified = NO; 
    [self performSelector:@selector(onRequestTimeout) withObject:nil afterDelay:5.0]; // 5 secs 
} 

- (void)onReachabilityChanged:(NSNotification *)note 
{ 
     // Do whatever on notification 
     notified = YES; 
} 

- (void) onRequestTimeout 
{ 
    if (!notified) 
    { 
     // Do whatever on request timeout 
     [[NSNotificationCenter defaultCenter] removeObserver:self name:@"kNetworkReachabilityChangedNotification" object:nil]; 
    } 
} 
Questions connexes