Error Domain=NSURLErrorDomain Code=-1005 “The netw

2018-12-31 08:52发布

I have an application which works fine on Xcode6-Beta1 and Xcode6-Beta2 with both iOS7 and iOS8. But with Xcode6-Beta3, Beta4, Beta5 I'm facing network issues with iOS8 but everything works fine on iOS7. I get the error "The network connection was lost.". The error is as follows:

Error: Error Domain=NSURLErrorDomain Code=-1005 "The network connection was lost." UserInfo=0x7ba8e5b0 {NSErrorFailingURLStringKey=, _kCFStreamErrorCodeKey=57, NSErrorFailingURLKey=, NSLocalizedDescription=The network connection was lost., _kCFStreamErrorDomainKey=1, NSUnderlyingError=0x7a6957e0 "The network connection was lost."}

I use AFNetworking 2.x and the following code snippet to make the network call:

AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
[manager setSecurityPolicy:policy];
manager.requestSerializer = [AFHTTPRequestSerializer serializer];
manager.responseSerializer = [AFHTTPResponseSerializer serializer];

[manager POST:<example-url>
   parameters:<parameteres>
      success:^(AFHTTPRequestOperation *operation, id responseObject) {
          NSLog(@“Success: %@", responseObject);
      } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
          NSLog(@"Error: %@", error);
      }];

I tried NSURLSession but still receive the same error.

27条回答
不再属于我。
2楼-- · 2018-12-31 09:29

I was receiving this error and also notices that the application Postman was also falling but was working in app Advanced Rest Client (ARC) and working in Android. So i had to install Charles to debug the communication and I notices that response code was -1. The problem was that REST programmer forgot to return response code 200.

I hope that this help other developers.

查看更多
素衣白纱
3楼-- · 2018-12-31 09:30

I was getting the error even on ios7 device when I was using xcode 6.2 beta. switching back from xcode 6.2 beta to 6.1.1 fixed the issue. at least on ios7 device.

查看更多
看风景的人
4楼-- · 2018-12-31 09:30

Restarting the computer fixed the issue for me with Xcode9.1. I had restarted the simulator and Xcode, it doesn't work.

查看更多
裙下三千臣
5楼-- · 2018-12-31 09:31

The iOS 8.0 simulator runtime has a bug whereby if your network configuration changes while the simulated device is booted, higher level APIs (eg: CFNetwork) in the simulated runtime will think that it has lost network connectivity. Currently, the advised workaround is to simply reboot the simulated device when your network configuration changes.

If you are impacted by this issue, please file additional duplicate radars at http://bugreport.apple.com to get it increased priority.

If you see this issue without having changed network configurations, then that is not a known bug, and you should definitely file a radar, indicating that the issue is not the known network-configuration-changed bug.

查看更多
低头抚发
6楼-- · 2018-12-31 09:31

I was facing the same issue, I have enabled Network Link Conditioner for slow network testing for the app. That was creating this error some times, When i have disabled it from Settings > Developer > Network Link Conditioner, it solved my problem.

enter image description here

Hope this help someone.

查看更多
琉璃瓶的回忆
7楼-- · 2018-12-31 09:32

I was connecting via a VPN. Disabling the VPN solved the problem.

查看更多
登录 后发表回答