如何为RESTKIT对象pipe理器设置超时间隔

我正在使用RESTKIT对象pipe理器从我的服务器获取信息。 我的实现代码片段如下:

-(void)getObjects { //Instantiate the RestKit Object Manager RKObjectManager *sharedManager = [RKObjectManager sharedManager]; //show the spinner [self showLoading]; //call server with the resourcepath [sharedManager loadObjectsAtResourcePath:self.resourcePath delegate:self]; } - (void)objectLoader:(RKObjectLoader*)objectLoader didLoadObjects:(NSArray*)objects { // handling in scenarios of empty arrays if ( [objects count]==0 ){ [self hideLoading]; if (emptyHandler){ emptyHandler(); }else{ [self standardEmptyHandling]; } return; } // planned failure if ( [[objects objectAtIndex:0] isKindOfClass:[Failure class]]){ NSAssert([objects count]==1,@"object returned is type failure, but there are more than one object in it"); failureObject=[objects objectAtIndex:0]; [self hideLoading]; [self standardErrorHandling]; return; } //return completion block to caller completionHandler(objects); } 

但是,可能会出现服务器错误或可达性错误,从而导致进程在终止之前持续很长的时间(微调控器将显示一段延长的时间)。

有没有办法在我的实现中设置超时时间,以便我可以提示用户提醒,以便在20秒内没有响应的情况下再次尝试?

这已经被RestKit贡献者在这个拉取请求https://github.com/RestKit/RestKit/pull/491中解决了,可以很容易的设置如下:

 RKObjectManager *objectManager = [RKObjectManager objectManagerWithBaseURL:@"http://..."]; objectManager.client.timeoutInterval = 30.0; // 30 seconds 

苹果公司对URL请求的默认超时时间是60秒。

以下是关于RestKit中未决问题的讨论:

http://groups.google.com/group/restkit/browse_thread/thread/8672eba8b1901f5d

NSTimer可能是一个简单的方法。

 #pragma mark - RKRequestDelegate - (void)requestDidStartLoad:(RKRequest *)request { [NSTimer scheduledTimerWithTimeInterval:20.0 target:self selector:@selector(handleRequestTimeout) userInfo:nil repeats:NO]; }