【问题标题】:How to check for request time out , is there a notification I can set?如何检查请求超时,我可以设置通知吗?
【发布时间】:2009-12-14 12:35:56
【问题描述】:

我想检查请求是否在一段时间后超时。

我知道 NSNotifiactionCenter ,但不知道如何为其设置请求超时通知。

谢谢。

【问题讨论】:

    标签: iphone timeout request nsnotification


    【解决方案1】:

    如果到那时还没有收到通知请求,您可以使用计时器并取消您的通知请求吗?

    例如以 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];
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-20
      • 1970-01-01
      • 1970-01-01
      • 2013-05-12
      • 1970-01-01
      相关资源
      最近更新 更多