ios 如何从 iPhone 模拟器访问主机本身
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6077888/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I access the host machine itself from the iPhone simulator
提问by Jordan Walsh
I'm developing an app that connects to a web service for most of it's operations. As a shortcut, I'd like to run a copy of my development server on my machine. Question is:
我正在开发一个应用程序,该应用程序连接到 Web 服务的大部分操作。作为快捷方式,我想在我的机器上运行我的开发服务器的副本。问题是:
How/can I access the host machine's network (http in this case) from the iPhone simulator?
我如何/如何从 iPhone 模拟器访问主机的网络(在这种情况下为 http)?
I'm developing the web service alongside the app, so it would be helpful to have them both on the host machine, and then I can commit changes as needed.
我正在与应用程序一起开发 Web 服务,因此将它们都放在主机上会很有帮助,然后我可以根据需要提交更改。
回答by jaminguy
The iOS Simulator uses the host machine network so you should be able to just use localhost or your machines IP address, whichever IP your web service is listening on.
iOS 模拟器使用主机网络,因此您应该能够仅使用 localhost 或您的机器 IP 地址,无论您的 Web 服务正在侦听哪个 IP。
回答by unixeO
In swift 5 just call:
在 swift 5 中只需调用:
http://localhost:<port>/file_path
but you will need to add this part to the project Info.plist
.
但是您需要将此部分添加到项目中Info.plist
。
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
Otherwise this error is going to happen.
否则就会出现这个错误。
Cannot start load of Task <xx-xx>.<x> since it does not conform to ATS policy.
Cannot start load of Task <xx-xx>.<x> since it does not conform to ATS policy.