2012-12-13 27 views

Trả lời

5

RestKit bây giờ sử dụng AFNetworking cho lớp HTTP của nó, vì vậy bạn cần đặt nó trong HTTPClient of Restkit. See this Issue trên AFNetworking Github. Ngoài ra, Matt người sáng tạo của AFNetworking không thực sự thích ý tưởng mở một tài sản thời gian chờ một cách dễ dàng (see his reason here)

Tôi hy vọng điều này có thể cung cấp cho bạn một số thông tin chi tiết!

+0

Có vẻ như không phải là một cách để thiết lập thời gian chờ trong RestKit 2.0 HTTPClient. –

5

Subclass RKHTTPRequestOperation và thực hiện các phương pháp

- (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

Không hoạt động đối với tôi. RestKit0.26.0 Tôi sẽ thử phương pháp này http://stackoverflow.com/a/16885658/3389683 –

2

Hoàn Mã

Để trở thành phức tạp hơn/mô tả, mã của tôi được như sau:

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 

Sau đó (và đây là phần mà giúp tôi biết, mà không được đề cập trong câu trả lời khác), đăng ký, bạn lớp với RKObjectManager.

Giống như (Hãy tha thứ cho sự mâu thuẫn của tôi, đây là phân khúc duy nhất của tôi mã trong nhanh chóng không khách quan c):

RKObjectManager.sharedManager().registerRequestOperationClass(Timeoutable); 
Các vấn đề liên quan