1

I'm currently working on an application tied to a nodejs localhost database API. When I test on the iOS simulator, I am getting API data back successfully. However, when I try to test on the iOS device, the application is still making a HTTP request to the localhost API and failing to retrieve the API data.

My question is, is it possible to somehow set up the localhost database API to work on the actual iOS device? if so, what is the best way of going about it?

thank you

5
  • 1
    You do realize that "localhost" means the host that the app is running on, right? So when you run your iOS app on a real iOS device, the database must also be running on the iOS device, not your computer. Commented Feb 6, 2017 at 15:14
  • 1
    Yes, I do realize that. But was wondering if there's any xcode setting I could potentially use while my device is connected to my test machine so it points to localhost on my test machine rather than look for it on my iOS device. Commented Feb 6, 2017 at 15:17
  • When the app is on your iOS device and the database is on your computer, then the database is no longer on "localhost". It's on a different host. You would need to change the app's code or configuration to point to your computer instead of localhost. Commented Feb 6, 2017 at 15:19
  • So it seems the best way to go about this is to put my 'localhost' data on a live server so its no longer local :/ was hoping there was an easier way.. thank you though~! Commented Feb 6, 2017 at 15:20
  • 1
    @GeorgeCastan100, what you are looking for is not localhost (127.0.0.1), but some local network, maybe (192.168.x.y) or (10.z.x.y); your web-server (if you have any) can manage that nicely for you, if you configure it. Commented Feb 6, 2017 at 15:46

1 Answer 1

1

There is a simple fix that will allow your iOS app to connect to your localhost server. What you need is a tunnel that will push your HTTP GET, POST, PUT, and DELETE messages from a device to your local server and return your localhost response back to the client. I wrote a blog article on this very thing with a video that walks you through it. I used ngrok.com. I DO NOT get any kickbacks for recommending them. You can have your localhost server interacting with your deployed mobile app, as well as your app running on your simulator.

The Blog Post: http://markzfilter.com/connect-ios-android-app-local-host-server/

The Service I Use (FREE): https://ngrok.com/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.