Request timeout in restkit 0.20.0

I did not find a way to set the timeout interval for restkit 0.20.0.

Can someone help increase the timeout interval.

thanks

+7
source share
3 answers

RestKit now uses AFNetworking for this HTTP layer, so you need to install it in HTTPClient Restkit. See this question on AFNetworking Github. Also, Matt, creator of AFNetworking, doesn't really like the idea of ​​easily opening the timeout property ( see His reason here )

I hope this can give you some ideas!

+5
source

Subclass RKHTTPRequestOperation and Implementation 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]; } 
+5
source

Full code

To be more complex / 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 part that helped me find out what was not mentioned in the other answers), register your class with RKObjectManager .

So (Forgive my inconsistency, this is my only code segment in quickly not a lens c ):

 RKObjectManager.sharedManager().registerRequestOperationClass(Timeoutable); 
+2
source

All Articles