ChatGPT解决这个技术问题 Extra ChatGPT

How do I access the host machine itself from the iPhone simulator

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:

How/can I access the host machine's network (http in this case) from the iPhone simulator?

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.

what's the setup for your development server?
Are you wondering what libraries to use in the iOS SDK? You should just be able to provide the URL string, i.e. "localhost:####/myURL".

j
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.


Expanding on jaminguy's answer, MAC OSX also has a built in Apache server. Just do a quick google search.....
How can you find out what port is used?
The port depends on your web server settings
Is it possible to do this from a device connected via USB?
@IanWarburton no any seperate device will require your computers IPv4 address. (If both devices are not on the same network it's more complicated)
u
unixeO

In swift 5 just call:

http://localhost:<port>/file_path 

but you will need to add this part to the project 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.


This answer will work, but it is not a good way of approaching this. Apple strongly discourages developers from arbitrarily loading urls and your app will NOT be accepted to the store if you use this approach. Please see this answer stackoverflow.com/questions/31254725/… to see how to correctly whitelist specific domains in your app
Right, only use this approach on development.