2012-12-13 40 views

回答

5

RestKit现在使用AFNetworking为它的HTTP层,所以你需要将其设置在Restkit的HttpClient的。 AFNetworking Github上的See this Issue。另外,AFNetworking的创建者Matt并不喜欢轻松打开超时属性的想法(see his reason here

我希望这能给你一些见解!

+0

似乎没有被设置在超时的方式RestKit 2.0 HTTPClient。 –

5

子类RKHTTPRequestOperation和实现方法

- (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]; 
} 
+0

不适用于我。 RestKit0.26.0我将尝试这种方法http://stackoverflow.com/a/16885658/3389683 –

2

完整代码

更精细/描述性的,我的代码是如下:

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 

然后(这是帮助我知道,这是不是在其他的答案中提到的部分),您注册类RKObjectManager

像这样(请原谅我的矛盾,这是迅速没有目标C我的代码只有段):

RKObjectManager.sharedManager().registerRequestOperationClass(Timeoutable);