2012-12-13 82 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);