views:

63

answers:

1

Hello all

I want to check for whether the request has timed out after some period.

I know NSNotifiactionCenter ,but don't know how to set the request time out notification for it.

thanks.

+2  A: 

You could just use a timer and cancel your notification request if not received by then?

e.g. taking Apple's reachability example:

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