6

Trying to set a request Timeout Interval on Restkit.

This post mentions HTTClient, but HTTPClient does NOT seem to have a way to set a timeout interval. Request timeout in restkit 0.20.0

Does anyone know how to set an interval?

Community
  • 1
  • 1
jdog
  • 10,351
  • 29
  • 90
  • 165

2 Answers2

12

There isn't direct access to it. You should really ask why you want to set a custom timeout.

If you do need to change it, you should subclass RKObjectManager and override requestWithObject:. Your implementation can just call super and then edit the resulting mutable request.

Wain
  • 118,658
  • 15
  • 128
  • 151
  • I don't use requestWithObject on Restkit. I use [[RKObjectManager sharedManager] postObject.... Is requestWithObject always called as the base of Restkit? Meaning does my postObject call eventually use requestWithObject. The reason for setting a timeout is Heroku resources go to sleep when not used for a certain time. If that happens I need Restkit to wait for Heroku to spin up (20 seconds). – jdog Jun 02 '13 at 18:10
  • Yes, it will be called as a result of postObject: because it's called by appropriateObjectRequestOperationWithObject: which is called by pretty much everything. – Wain Jun 02 '13 at 19:04
9

The following worked for me in RestKit 0.20.3: I construct the NSMutableRequest myself and set the timeout on this request. Unfortunately there is no way to set the default request timeout in RestKit 0.20.x due to AFNetworking's policy to not expose this property.

NSMutableURLRequest *request = [objectManager requestWithObject:nil method:RKRequestMethodGET path:@"test.json" parameters:nil];

[request setTimeoutInterval:300]; // set the timeout for this request to 5 minutes

RKManagedObjectRequestOperation *op = [[RKObjectManager sharedManager] managedObjectRequestOperationWithRequest:request managedObjectContext:[[[RKObjectManager sharedManager] managedObjectStore] mainQueueManagedObjectContext] success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
    NSLog(@"Success, %d results loaded", [mappingResult count]);
} failure:^(RKObjectRequestOperation *operation, NSError *error) {
    NSLog(@"Fail");
}];

[[RKObjectManager sharedManager] enqueueObjectRequestOperation:op];
masam
  • 2,268
  • 1
  • 22
  • 24
  • 1
    @Wain's comment below is the better of the answers as it will apply to RestKit's built-in *Object: methods (i.e. getObject: postObject: and putObject:). – Sandy Chapman Mar 13 '14 at 16:56