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.
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.
如果到那时还没有收到,您可以只使用计时器并取消您的通知请求吗?
例如,以 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];
}
}