Nik391 Nik391 - 1 month ago 34
Objective-C Question

NSURLErrorDomain code =-1001 request getting timed out

I am developing an iOS app that should send the data collected by sensors to a server. However I am only able to send the data for 1 min after that I get a following error:

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.}


Here is the code snippet that tries to send the data:

-(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];
}


How can I increase the timeout interval of 60 secs?
Any help would be very appreciated.

Answer

From the documentation:

Timeout

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

[UNIRest timeout:2];

By default the timeout is 60.

Comments