如何为 RESTKIT 对象管理器设置超时间隔 [英] How to set timeout interval for RESTKIT Object Manager
问题描述
我正在使用 RESTKIT 对象管理器从我的服务器获取信息.我的实现代码片段如下:
I am using the RESTKIT Object Manager to get information from my server. The snippet of my implementation code is as follows:
-(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);
}
但是,可能存在服务器错误或可达性错误的情况,这会导致进程在终止之前继续尝试很长时间(微调器将显示很长时间_.
However there might be cases whereby there is a server error or reachability error this causing the process to continue trying for a long duration before terminating (spinner will be displayed for an extended amount of time_.
有没有办法在我的实现中设置超时持续时间,例如,如果服务器在 20 秒内没有响应,我可以提示用户再次尝试?
Is there a way to set a timeout duration in my implementation so that I can prompt the user an alert to try again if the server does not respond in 20 secs for example?
推荐答案
RestKit 贡献者现在已经在这个拉取请求中解决了这个问题 https://github.com/RestKit/RestKit/pull/491 并且可以轻松设置如下:
This has now been resolved by RestKit contributors in this pull request https://github.com/RestKit/RestKit/pull/491 and can be set easily as follows:
RKObjectManager *objectManager = [RKObjectManager objectManagerWithBaseURL:@"http://..."];
objectManager.client.timeoutInterval = 30.0; // 30 seconds
这篇关于如何为 RESTKIT 对象管理器设置超时间隔的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!