我使用RestKit我的項目,我需要對我的要求有點像10-20分鐘的時間(600 - 1.1秒) 我能夠從1更改超時60秒,這工作沒有任何問題。但是當我嘗試設置更多60秒(90-9999999)時,60秒後我收到超時錯誤。有這樣的代碼在RKRequest.m:NSURLConnection GET 60秒超時最大值?
- (void)fireAsynchronousRequest {
RKLogDebug(@"Sending asynchronous %@ request to URL %@.", [self HTTPMethod], [[self URL] absoluteString]);
if (![self prepareURLRequest]) {
// TODO: Logging
return;
}
_isLoading = YES;
if ([self.delegate respondsToSelector:@selector(requestDidStartLoad:)]) {
[self.delegate requestDidStartLoad:self];
}
RKResponse* response = [[[RKResponse alloc] initWithRequest:self] autorelease];
_connection = [[NSURLConnection connectionWithRequest:_URLRequest delegate:response] retain];
[[NSNotificationCenter defaultCenter] postNotificationName:RKRequestSentNotification object:self userInfo:nil];
}
我加入NSURLConnection的初始化之前一行:
[_URLRequest setTimeoutInterval:1200];
但60秒之後再次接收超時錯誤。 RKResponse對象是NSURLconnection的委託。 所以我發現,在RKResponce.m 60秒委託梅託德被調用後(即使我嘗試[_URLRequest setTimeoutInterval:1200]後初始化NSURLConnection的對象):
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
RKResponseIgnoreDelegateIfCancelled();
_failureError = [error retain];
NSLog(@"Error %@", error);
[_request invalidateTimeoutTimer];
[_request didFailLoadWithError:_failureError];
}
它奇怪,我說,我不能讓超過60秒的NSURLConnection超時。
今天我創建了一個新項目來測試這個問題。我有這樣的代碼:
- (void)viewDidLoad
{
[super viewDidLoad];
NSURL *url = [NSURL URLWithString: @"http://5.9.10.68:8182"];
NSMutableURLRequest *urlRequest = [[NSMutableURLRequest alloc] initWithURL:url];
[urlRequest setHTTPMethod:@"GET"];
[urlRequest setTimeoutInterval:300.0];
NSLog(@"timeout %f",urlRequest.timeoutInterval);
NSURLConnection* urlConnection = [[NSURLConnection alloc] initWithRequest:urlRequest delegate: self];
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
NSLog(@"Error request %@", error);
}
因此,這裏的日誌:
2012-07-17 14:37:58.627 F [76799:F803]超時300.000000
2012-07-17 14:39 :14.488 f [76799:f803]錯誤請求錯誤域= NSURLErrorDomain代碼= -1001「請求超時。」 UserInfo = 0x687a690 {NSErrorFailingURLStringKey = http://5.9.10.68:8182 /,NSErrorFailingURLKey = http://5.9.10.68:8182 /,NSLocalizedDescription =請求超時,NSUnderlyingError = 0x687a070「請求超時。」}
所以timeout = 75,但不是300.很奇怪。
其實我的代碼看起來像:'RKObjectManager * manager = [RKObjectManager objectManagerWithBaseURLString:aBaseURL]; manager.client.timeoutInterval = 300;'但我發現它沒有RestKit問題。我發現與這個問題有關:[link](https://github.com/RestKit/RestKit/issues/852) – Andrew 2012-07-16 19:26:57