I didn't find any way to set the timeout interval on restkit 0.20.0.
Can anyone help to increase the timeout interval.
Thanks
Subclass RKHTTPRequestOperation and implement method
- (NSURLRequest *)connection:(NSURLConnection *)connection willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)redirectResponse
{
NSMutableURLRequest *requestWithTimeout = [request mutableCopy];
[requestWithTimeout setTimeoutInterval:30];
return [super connection:connection willSendRequest:requestWithTimeout redirectResponse:redirectResponse];
}
RestKit now use AFNetworking for it's HTTP layer, so you need to set it in the HTTPClient of Restkit. See this Issue on AFNetworking Github. Also, Matt the creator of AFNetworking does not really like the idea of opening up a timeout property easily (see his reason here)
I hope this can give you some insights!
To be more elaborate/descriptive, my code was as follows:
RKHTTPRequestOperation_Timeoutable.h
#import "RKHTTPRequestOperation.h"
@interface RKHTTPRequestOperation_Timeoutable: RKHTTPRequestOperation
- (NSURLRequest *)connection:(NSURLConnection *)connection willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)redirectResponse;
@end
RKHTTPRequestOperation_Timeoutable.m
#import "RKHTTPRequestOperation_Timeoutable.h"
@implementation RKHTTPRequestOperation_Timeoutable
- (NSURLRequest *)connection:(NSURLConnection *)connection willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)redirectResponse
{
NSMutableURLRequest *requestWithTimeout = [request mutableCopy];
[requestWithTimeout setTimeoutInterval:150];//2.5 minutes
return [super connection:connection willSendRequest:requestWithTimeout redirectResponse:redirectResponse];
}
@end
Then (and this is the the part that helped me to know, that wasn't mentioned in other answers), register you class with RKObjectManager.
Like so (Forgive my inconsistency, this is my only segment of code in swift not objective c):
RKObjectManager.sharedManager().registerRequestOperationClass(Timeoutable);