XCode 6 Simulator ignores hosts file changes

牧云@^-^@ 提交于 2019-12-18 13:16:38

问题


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?

|improve this question

回答1:


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.




回答2:


Have you tried flushing the DNS cache with the command

sudo dscacheutil -flushcache

before quitting and relaunching the iOS Simulator ?



来源:https://stackoverflow.com/questions/25973476/xcode-6-simulator-ignores-hosts-file-changes

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!