I’ve been running my iOS app in the Xcode simulator and it reaches my Vapor services at http://localhost:8080/api/ just fine but now I need to run the iOS app on an iPhone.
I tried changing the “localhost” part of baseURL in ResourceRequest.swift with my Mac’s IP address but still doesn’t work.
If there’s a section in the book about testing on a device I couldn’t find it.
Any pointers appreciated.
Hey @gonzalo so you have a couple of options. By default a Vapor application will only allow connections from the same IP address (basically on the same machine). So you need to set the hostname (or the allowed connections address) to
0.0.0.0 which tells the app to allow connections from any IP address.
You can do this two ways:
- Edit the Run scheme in Xcode and add an argument for
- In configure.swift register a
NIOServerConfig with the hostname set to
One you’ve done one of those, when you start the app you’ll see it say something like
server starting on http://0.0.0.0:8080
Hope that helps!
That worked! I do have the server URL set in two places so I needed to change it in ResourceRequest.swift and Auth.swift to include my Mac’s IP address. Now my iOS app running on my iPhone can reach my Vapor login and data services running on my Mac. Awesome!
Thank you so much. Stay well.