【发布时间】:2009-12-14 12:35:56
【问题描述】:
我想检查请求是否在一段时间后超时。
我知道 NSNotifiactionCenter ,但不知道如何为其设置请求超时通知。
谢谢。
【问题讨论】:
标签: iphone timeout request nsnotification
我想检查请求是否在一段时间后超时。
我知道 NSNotifiactionCenter ,但不知道如何为其设置请求超时通知。
谢谢。
【问题讨论】:
标签: iphone timeout request nsnotification
如果到那时还没有收到通知请求,您可以使用计时器并取消您的通知请求吗?
例如以 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];
}
}
【讨论】: