2009-12-14 2 views

답변

4

타이머를 사용하고 그때까지 수신되지 않으면 알림 요청을 취소 할 수 있습니까?

애플의 접근 가능성 예제 :

- (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]; 
    } 
}