1

しばらくしてリクエストがタイムアウトしたかどうかを確認したいのですが。

NSNotifiactionCenterは知っていますが、リクエストのタイムアウト通知を設定する方法がわかりません。

ありがとう。

4

1 に答える 1

4

それまでに受信されない場合は、タイマーを使用して通知要求をキャンセルできますか?

たとえば、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];
    }
}
于 2009-12-14T13:10:07.277 に答える