简体   繁体   English

iOS开发过程中实际设备与虚拟环境的通信

[英]Communication between the actual device and the virtual environment during iOS development

I'm developing for iOS with Flutter.我正在为 iOS 和 Flutter 开发。

I created a virtual environment on my Mac using Virtual BOX and Vagrant, and set up a server to process API requests and return results.我在我的 Mac 上使用 Virtual BOX 和 Vagrant 创建了一个虚拟环境,并设置了一个服务器来处理 API 请求并返回结果。

Example of API localhost:8888/api/result示例 API localhost:8888/api/result

The problem is this "localhost".问题是这个“本地主机”。

I built it with Android Studio and checked it with the simulator, and found that I could request localhost:8888/api/result and get the result back, no problem.我用Android Studio搭建,用模拟器查看,发现可以请求localhost:8888/api/result,得到结果,没问题。

However, when I checked on the actual iPhone device, I found that communication was not possible.但是,当我在实际的 iPhone 设备上查看时,我发现无法通信。 I think the cause is in localhost.我认为原因在于本地主机。

I expect that localhost will be the iPhone itself when built on the iPhone.我希望 localhost 在 iPhone 上构建时将是 iPhone 本身。

How should I communicate with the virtual environment on my local device at this time?这时候我应该如何与本地设备上的虚拟环境进行通信呢?

I want to make API requests to a virtual environment in my local terminal where I built iOS.我想在我构建 iOS 的本地终端中向虚拟环境发出 API 请求。

It was easy.很容易。 All I had to do was edit the Vagrantfile and set the public IP. Of course, it is in the same local.network.我所要做的就是编辑 Vagrantfile 并设置 public IP。当然,它在同一个 local.network 中。 I didn't have to specify the port, just request the API and I was good to go.我不必指定端口,只需请求 API,我对 go 很好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM