I am calling a webservice from my iOS app which can take up to four minutes to return. I am using RestKit for the call and loading of the objects. What I'm finding is that when the requests are taking a long time, I get a Timeout error after ~60 seconds. I have tried setting the timeoutInterval to absurd amounts but it still times out after ~60.
RKObjectManager* objectManager = [RKObjectManager objectManagerWithBaseURL:HOSTNAME];
objectManager.client.requestQueue.showsNetworkActivityIndicatorWhenBusy = YES;
objectManager.client.disableCertificateValidation = YES;
//timeout
objectManager.client.timeoutInterval = 1000;
Here is the call to the service:
- (void)loadData
{
NSString *uid = [self retrieveFromUserDefaults:@"login_preference"];
NSString *pwd = [self retrieveFromUserDefaults:@"password_preference"];
if([uid isEqualToString:@""] || [pwd isEqualToString:@""]){
[self stopSpinner];
[self enableUserInterface:YES];
UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"Missing Settings"
message:@"Please enter your login information in the settings."
delegate:nil
cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
return;
}
RKObjectManager* objectManager = [RKObjectManager sharedManager];
NSDictionary *params = [NSDictionary dictionaryWithObjects:
[NSArray arrayWithObjects:uid, pwd, nil]
forKeys:[NSArray arrayWithObjects:@"uid", @"pwd", nil]];
// Load the object model via RestKit
[objectManager loadObjectsAtResourcePath:[@"/synchData" appendQueryParams:params] delegate:self];
}
I'm doing the call to the webservice in a background thread - is there something in that design that could be causing the problem? I can't imagine what, like iOS not letting background threads run for longer than 60 seconds? I just can't figure out what is the problem.
Is the timeout the time it takes to get a response from the server, or to get the WHOLE response from the server? I am returning a potentially very large json response - do I need to return the whole thing within the timeout limit, or do I just need to get any response from the server within the limit?
If I understand your problem, the solution would be:
- (void)request:(RKRequest *)request didFailLoadWithError:(NSError *)error
So when you have problem with timeout interval, it will be caught at this method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With