[英]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.我正在 MacOS XCode 12.3、模拟器 iOS 14.3 上开发,试图连接到本地网络上机器上的开发服务器。 I have an entry in
/etc/hosts
specifying the address of the development server.我在
/etc/hosts
中有一个条目,指定了开发服务器的地址。 This used to work, and still works in Mac applications.这曾经有效,现在仍然适用于 Mac 应用程序。
The app in the simulator cannot access the server .模拟器中的应用程序无法访问服务器。 Safari in the simulator also cannot access the server.
模拟器中的Safari也无法访问服务器。
The log shows nil host used in call to allowsSpecificHTTPSCertificateForHost
and nil host used in call to allowsAnyHTTPSCertificateForHost:
日志显示
nil host used in call to allowsSpecificHTTPSCertificateForHost
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
.我已将
Allow Arbitrary Loads in Web Content
中的Allow Arbitrary Loads
和 Allow Arbitrary Loads 设置为 true,并将服务器添加到Info.plist
的Exception Domains
中。
How can I resolve this issue?我该如何解决这个问题?
It turns out that the simulator no longer uses /etc/hosts
.事实证明,模拟器不再使用
/etc/hosts
。 I set up a local DNS server dnsmasq
and that allowed the simulator to access the server again.我设置了一个本地 DNS 服务器
dnsmasq
并允许模拟器再次访问服务器。
See https://zhimin-wen.medium.com/setup-local-dns-server-on-macbook-82ad22e76f2a见https://zhimin-wen.medium.com/setup-local-dns-server-on-macbook-82ad22e76f2a
Replace <servername>
and <ipaddress>
with your details.将
<servername>
和<ipaddress>
替换为您的详细信息。
> 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:测试 DNS 服务:
> dig <servername> @localhost +short
> 192.168.20.21
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.