0
votes

I am working on an application in Xcode 6.1, iOS 8.1; the application was working completely fine till 2 days before, but today as I executed it I got an error in the web service & the error is printed below.

Error: Error Domain=NSURLErrorDomain Code=-1001 "The request timed out." UserInfo=0x7c6899b0 {NSErrorFailingURLStringKey=<URL>, NSErrorFailingURLKey=<URL>, NSLocalizedDescription=The request timed out., NSUnderlyingError=0x7c688f60 "The request timed out."}

I had used AFNetworking 2.x and following code snippet to make network call:

AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.requestSerializer = [AFJSONRequestSerializer serializer];
manager.responseSerializer = [AFJSONResponseSerializer serializer];
manager.responseSerializer.acceptableContentTypes=[manager.responseSerializer.acceptableContentTypes setByAddingObject:@"text/html"];

[manager POST:<URL>
   parameters:<parameters>
      success:^(AFHTTPRequestOperation *operation, id responseObject) {

          NSLog(@"JSON: %@", responseObject);
          NSError *error = nil;
          NSDictionary *JSON = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingAllowFragments error:&error];
          if (error) {
              NSLog(@"Error serializing %@", error);
          }
          NSLog(@"Dictionary %@", JSON);
          NSLog(@"Success");
      }
      failure:^(AFHTTPRequestOperation *operation, NSError *error) {
          NSLog(@"Error: %@", error);
      }]; 
}
2
Well thats what happens with networking and server access sometimes. Your code design has to deal with the possibility the network is down or the server is down or it might be incredibly slow etc.Gruntcakes

2 Answers

2
votes

You can set time interval for request

[manager.requestSerializer setTimeoutInterval:100];
-1
votes

You can set time interval for request

[manager.requestSerializer setTimeoutInterval:150];

If server give response after time interval 60 sec.then it is useful.