gpt4 book ai didi

objective-c - 如何为 RESTKIT 对象管理器设置超时间隔

转载 作者:可可西里 更新时间:2023-11-01 05:04:12 26 4
gpt4 key购买 nike

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

-(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

关于objective-c - 如何为 RESTKIT 对象管理器设置超时间隔,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7713958/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com