如何设置RESTKIT对象管理器的超时间隔

Zhe*_*hen 4 objective-c settimeout ios restkit

我正在使用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);

}
Run Code Online (Sandbox Code Playgroud)

但是,可能存在服务器错误或可达性错误的情况,这导致进程在终止之前继续尝试很长时间(微调器将显示延长的时间量_.

有没有办法在我的实现中设置超时持续时间,以便我可以提示用户提醒如果服务器在20秒内没有响应,例如?

pch*_*10k 11

这个拉取请求https://github.com/RestKit/RestKit/pull/491中的RestKit贡献者现在已经解决了这个问题,可以轻松设置如下:

RKObjectManager *objectManager = [RKObjectManager objectManagerWithBaseURL:@"http://..."];
objectManager.client.timeoutInterval = 30.0; // 30 seconds
Run Code Online (Sandbox Code Playgroud)

  • 在restkit 0.25中,这不再适用了.任何建议? (3认同)