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

IosIphoneIpad

Ios Problem Overview


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.

Ios Solutions


Solution 1 - Ios

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.

Solution 2 - Ios

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJordan WalshView Question on Stackoverflow
Solution 1 - IosjaminguyView Answer on Stackoverflow
Solution 2 - IosunixeOView Answer on Stackoverflow