2016-10-12 122 views
0

我正在開發一個iOS應用程序,它應該將傳感器收集的數據發送到服務器。但是我只能在那之後,我收到了以下錯誤發送數據,1分鐘:NSURLErrorDomain代碼= -1001請求超時

submit error = Error Domain=NSURLErrorDomain Code=-1001 "The request timed out." UserInfo={NSUnderlyingError=0x1469a9820 {Error Domain=kCFErrorDomainCFNetwork Code=-1001 "The request timed out." UserInfo={NSErrorFailingURLStringKey=http://xyz/abc/, NSErrorFailingURLKey=http://xyz/abc/, _kCFStreamErrorCodeKey=-2102, _kCFStreamErrorDomainKey=4, NSLocalizedDescription=The request timed out.}}, NSErrorFailingURLStringKey=http://xyz/abc/, NSErrorFailingURLKey=http://xyz/abc/, _kCFStreamErrorDomainKey=4, _kCFStreamErrorCodeKey=-2102, NSLocalizedDescription=The request timed out.} 

這裏是試圖發送數據的代碼片段:

-(void)postData:(NSString*)postTo withParameters:(NSDictionary*)parameters withHeaders:(NSDictionary*)headers{ 
    [[UNIRest post:^(UNISimpleRequest *request) { 
     [request setUrl:[NSString stringWithFormat:@"%@%@", BASE_URL, postTo]]; 
     [request setHeaders:headers]; 
     [request setParameters:parameters]; 
    }] asJsonAsync:^(UNIHTTPJsonResponse* response, NSError *error) { 
     if (error) { 
      NSLog(@"submit error = %@", error); 
      return; 
     } 
     else 
     { 
      NSLog(@"submit to %@ success", [NSString stringWithFormat:@"%@%@/", BASE_URL, postTo]); 
     } 
    }]; 
} 
NSDictionary* headers = @{@"accept": @"application/json"}; 
for (int i = 0; i < sensorDataLength; i++) { 
     SensorData *Obj = [SensorArray objectAtIndex:i]; 
     NSDictionary* parameters = @{@"x": [NSString stringWithFormat:@"%f", Obj.xAxis], @"y": [NSString stringWithFormat:@"%f", Obj.yAxis]}; 

     [self postData:@"abc/" withParameters:parameters withHeaders:headers]; 
    } 

我怎樣才能提高60秒的超時間隔? 任何幫助將不勝感激。

回答

0

documentation

超時

You can set a custom timeout value (in seconds):

[UNIRest timeout:2]; 

By default the timeout is 60.

+0

酷非常感謝這很簡單! – Nik391