Yoshkebab
Yoshkebab

Reputation: 800

XCode 6 Simulator ignores hosts file changes

I have a client-server App, in order to test it with Simulator I have a server on a virtual machine and I change mac's hosts file (/etc/hosts) so I can get there.

It works fine in XCode 5, but on XCode 6 the server cannot be reached. When trying to open an NSURLConnection to it I get -

Error Domain=kCFErrorDomainCFNetwork Code=310 "There was a problem communicating with the secure web proxy server (HTTPS)." UserInfo=0x78b3fc50 {_kCFStreamErrorCodeKey=-2096,
NSErrorFailingURLStringKey=https://xxx.yyy.zzz/mobile/login, NSErrorFailingURLKey=https://xxx.yyy.zzz/mobile/login, NSLocalizedDescription=There was a problem communicating with the secure web proxy server (HTTPS)., _kCFStreamErrorDomainKey=4, NSLocalizedRecoverySuggestion=Please check your proxy settings. For help with this problem, contact your system administrator.

Of course the server can be reached from Safari by typing https://xxx.yyy.zzz, it answers to ping and it still works if I turn on XCode 5.

I figure that the Simulator ignores the changes for the mac's hosts file, or maybe it uses it's own private hosts file.

If I enter some "hard coded resolving" (translating in the code the xxx.yyy.zzz to it's ip address) the server can be reached.

Anyone has any idea how to solve this?

Upvotes: 13

Views: 8739

Answers (3)

Thibault D.
Thibault D.

Reputation: 10004

IPv6

If all of: your application, your mac, your network, DNS and your backend support IPv6, you need to edit the hosts file with an IPv6 entry.

2001:0db8:85a3:0000:0000:8a2e:0370:7334 example.com

It seems that IPv6 resolves first so any IPv4 entry in the hosts file will be ignored if there is a working IPv6 infrastructure.

Upvotes: 0

DUzun
DUzun

Reputation: 1722

Solution:

Make sure you add each host alias on different line:

# Wrong!
  127.0.0.1 example.com www.example.com

# Good
  127.0.0.1 example.com
  127.0.0.1 www.example.com

My story:

I had the same issue with Xcode 6.

There is a bug or behaviour change in OSX related to /etc/hosts.

If I add more host aliases on the same line in OSX's /etc/hosts file, iOS simulator gives me the same error. But if I add each host alias on it's own line, iOS simulator works as I expect it to.

Upvotes: 19

Cyrille
Cyrille

Reputation: 25144

Have you tried flushing the DNS cache with the command

sudo dscacheutil -flushcache

before quitting and relaunching the iOS Simulator ?

Upvotes: 4

Related Questions