Tôi không tìm thấy bất kỳ cách nào để đặt khoảng thời gian chờ trên bộ lưu trữ 0.20.0.Yêu cầu hết thời gian trong bộ lưu trữ 0.20.0
Bất kỳ ai cũng có thể giúp tăng khoảng thời gian chờ.
Cảm ơn
Tôi không tìm thấy bất kỳ cách nào để đặt khoảng thời gian chờ trên bộ lưu trữ 0.20.0.Yêu cầu hết thời gian trong bộ lưu trữ 0.20.0
Bất kỳ ai cũng có thể giúp tăng khoảng thời gian chờ.
Cảm ơn
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!
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];
}
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 –
Để 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ó vẻ như không phải là một cách để thiết lập thời gian chờ trong RestKit 2.0 HTTPClient. –