133

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.

pnuts
  • 58,317
  • 11
  • 87
  • 139
Jordan Walsh
  • 1,505
  • 2
  • 9
  • 8

2 Answers2

166

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.

jaminguy
  • 25,840
  • 2
  • 23
  • 21
20

Develop solution (Not suitable for production).

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.

unixeo
  • 1,116
  • 1
  • 15
  • 28
  • 3
    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 https://stackoverflow.com/questions/31254725/transport-security-has-blocked-a-cleartext-http to see how to correctly whitelist specific domains in your app – Olyve Oct 30 '19 at 18:43
  • 3
    Right, only use this approach on development. – unixeo Oct 30 '19 at 21:30