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_.
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?