Search code examples
iosnetwork-programmingios-simulator

iOS simulator cannot connect to development server


I am developing on MacOS XCode 12.3, simulator iOS 14.3 attempting to connect to a development server on a machine on the local network. I have an entry in /etc/hosts specifying the address of the development server. This used to work, and still works in Mac applications.

The app in the simulator cannot access the server. Safari in the simulator also cannot access the server.

The log shows nil host used in call to allowsSpecificHTTPSCertificateForHost and nil host used in call to allowsAnyHTTPSCertificateForHost:

I have set Allow Arbitrary Loads and Allow Arbitrary Loads in Web Content to true and added the server to Exception Domains in Info.plist.

How can I resolve this issue?


Solution

  • It turns out that the simulator no longer uses /etc/hosts. I set up a local DNS server dnsmasq and that allowed the simulator to access the server again.

    See https://zhimin-wen.medium.com/setup-local-dns-server-on-macbook-82ad22e76f2a

    Replace <servername> and <ipaddress> with your details.

    > brew install dnsmasq
    > cp /usr/local/etc/dnsmasq.conf /usr/local/etc/dnsmasq.conf.orig
    > echo "conf-dir=/usr/local/etc/dnsmasq.d/,*.conf" > /usr/local/etc/dnsmasq.conf
    > echo "address=/<servername>/<ipaddress>" > /usr/local/etc/dnsmasq.d/<servername>
    > sudo mkdir -p /etc/resolver 
    > echo "nameserver 127.0.0.1"> /etc/resolver/<servername>
    > sudo brew services start dnsmasq
    

    Test the DNS service:

    > dig <servername> @localhost +short
    > 192.168.20.21