32

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=, NSErrorFailingURLKey=, 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);
      }]; 
}

UPDATE: I had done quit/relaunched the iOS Simulator.app, reseted content & settings, but nothing worked.

Muhammad Nabeel Arif
  • 19,140
  • 8
  • 51
  • 70
iYoung
  • 3,596
  • 3
  • 32
  • 59

8 Answers8

30

There was no issue in the code. I guess the simulator internally was not able to connect to the internet, so that is why it was not able to connect to the server after providing various timeout intervals. But it worked completely fine when I executed another day. Thanks to @Andrew Jaffee for helping me to find this issue.

iYoung
  • 3,596
  • 3
  • 32
  • 59
12

iOS Simulator -> Reset Content and Settings; worked for me

Babac
  • 931
  • 11
  • 21
10

Had this problem and had a different resolution so I thought I'd add it here:

Basically, I was sending some parameters when it should have been a clean GET request. Deleted the parameters, GET request worked just fine.

Jan Papenbrock
  • 1,037
  • 1
  • 11
  • 24
agrippa
  • 819
  • 10
  • 8
7

I was calling local server connection and was getting this error. I was using different network in my device and phone. When I connected both to same wifi, it worked.

pacholik
  • 8,607
  • 9
  • 43
  • 55
shamna
  • 111
  • 1
  • 6
  • I was using the simulator, but was connected to both ethernet and wifi networks. Disconnected the "extra" network, and reset simulator content and settings. Worked fine! (Also, was actually getting `NSURLErrorDomain Code=-1005`) – leanne Feb 13 '17 at 18:38
3

This can happen if your network configuration changes while the simulator is running. Please reboot the simulator runtime (eg: quit/relaunch the iOS Simulator.app) and that will likely fix your problem.

If the problem persists, please update your question to indicate that the issue you are experiencing is not this known problem. Thanks.

Jeremy Huddleston Sequoia
  • 22,938
  • 5
  • 78
  • 86
  • I have checked, my network configuration is not changing it is same in whole process. I had done all things which I knew, quit/relaunched the iOS Simulator.app, reseted content & settings... but nothings worked. – iYoung Nov 18 '14 at 04:15
0

Ok, I lost a lot of time investigeting similar issue.

In my case the problem was strange (bad?) firewall on the server. It was banning device when there was many (not so many) requests in short period of time.

I believe you can do easy test if you are facing similar issue.

  1. Send a lot of (depends of firewall settings) requests in loop (let's say 50 in 1 second).
  2. Close/Kill app (this will close connections to server)
  3. (OPTIONAL) Wait a while (lets say 60 seconds)
  4. Start app again and try send request

If you now got timeout for all next requests, you probably have same issue and you should talk

with sever guys.

PS: if you don't have access to server you can give user info that he should restart wifi on device to quit that timeout loop. It could be last resort in some cases.

Szuwar_Jr
  • 683
  • 8
  • 11
0

I am working for an enterprise company so we use VPN for connecting our web services.

My computer connected to VPN so my simulators (xcode simulator) could VPN but my own iPhone (real phone) was not connected to VPN so the issue occur for this reason your simulator should be connected to URLs

Kidly check your URL in the simulator.

Metin Atalay
  • 1,375
  • 18
  • 28
-2

You must close the firewall and it will work. I tried this solution and it worked for me.

jeprubio
  • 17,312
  • 5
  • 45
  • 56