iOS + Web Services + Intranet - ios

On the mac, we can easily update the 'hosts' file and send a web-service hit to local server, and get the required data (faster). Can we do something similar if the Server and iOS application are both under the same Wifi network (for example)?

I don't think there is a 'hosts' file for the iOS devices. But you can use bonjour service to advertise your server over local WiFi network. Your iOS app can use bonjour to discover such servers.

I guess what you could do to point your iPad to a local server even when accessing a global url is this, if I understand your question right:
Create a WIFI network on your Mac
Update the hosts file on your Mac and let the "global" address point to your local service
Now when you access the "global" address on your iPad it will go via your Mac and will therefore point to the local machine
I hope this helps

I don't think one has access to a kind of hosts file in iOS, but you can definitely access servers in your local network using Bonjour.
<hostname>.local

Related

How do I connect to a server on a dev machine?

I have a REST API on my dev machine. If an app is running on a real device, how do I connect?
At present, I am looking up the IP address of the machine on the local network and setting that as the domain in the app's Info.plist.
However, this is a nightmare because the IP address changes everywhere I go and sometimes it inexplicably won't connect.
Is there an easier way of doing this?
I've used OHHTTPStubs to deal fake data. At least now I can work on the UI without needing to be concerned with the network.

Accessing remotely my web service

I have implemented a web service on my mac and I am able to access its functionalities through the url "http://localhost:8080/ServiceApp-war/resources/".
As I got satisfying results that I could see in the iPhone simulator in Xcode, I decided to connect my iPhone and test on it. But for this to work I think I need to change the "localhost" in my URL to the IP address of my mac.
I tried to replace it with my public IP address and I got a "could not connect to the server" error on my console. I also tried to replace "localhost" with the IP address I found in System Preferences-->Network-->Wi-Fi and I could see that it was working on the simulator but still nothing when I connect my iPhone and run the application on it.
Please provide a solution for accessing my web service remotely.
Thank you.
Create hotspot from your mac, connect to it with your iPhone and try again.
<lame solution>
Try some service for temporary domain, it will make your computer accessible from anywhere.
How do you "connect" your iPhone? USB connection does not create a network. Well, it does create if you turn on Personal Hotspot on your iPhone (maybe in some other cases, dunno). But the most simple way is to connect Mac and iPhone to the same WiFi network.
Once connected, you can use any of "ping" apps available on App Store. Just look for "ping" (some kind of "network reachability test" or so). You can check if your Mac is really reachable on the network.
If it's not reachable, check your network settings on both devices: do they belong to the same subnet, do they use the same gateway, etc.
If your Mac is reachable with ping, then you should deal with your web service. I setup the web server (which is already distributed within OS X): it already has all the settings to allow other devices to connect. But your web service may require some additional setup. It's two basic things: it should bind to your IP address (please check http://YOUR.IP:8080/ServiceApp-war/resources/ from your Mac!) and second, accept incoming connections from other agents, you should find it somewhere in its settings.
Ngrok was the perfect solution I was looking for.
https://ngrok.com
You could also try finch, which is similar to ngrok. It has a nice friendly GUI. https://meetfinch.com

Accessing the Local server from iOS over Wifi

My development environment is:
I have a Server application running on the windows and modified host.dat file to map to IP address with server url something like that
192.168.1.220 server.dev.com
192.168.1.221 server-rc.dev.com
to access these servers from Mac application I had to modify mac host file and it seems to be running fine till now.
Now I need to access the local server from iPhone, all the machines are in same wifi, is there any way to access the server application which is running over the window in my private network,
Googling the same problem, it says I need to setup the DNS name in the router, but I am not getting how to do the same.
Update:
From the iPhone simulator I am able to access server, problem coming only form the device.
Thanks for looking at it,
Making use of Fiddler, I could resolve this issue.
Detailed example here

Connect iPhone to local server for testing on XCode? -- without using WiFi

So I have an ejabberd (XMPP) server setup on my MacBook. Connects fine with Simulator, only intermittently on the device. The two times it hasn't connected were at cafes that had sign-on gateways for their Wi-Fi. I know nothing when it comes to networks, but I'm guessing this is a Firewall thing?
I'm supposing I can't get around the firewall without an elaborate workaround.
I've found that turning off Wi-Fi on both devices and turning on tethering so that both devices are communicating via data works. However, I'd rather not do this as my data plan is limited and I'd like to be freely internet-connected while I work.
Is there a way to setup XCode to have the phone use the USB connection to access the server on the MacBook? Or maybe some other way I'm not imagining?
Bluetooth doesn't work.
I don't believe that the problem is with some kind of firewall on the network…
Try using the local IP address instead of the hostname, It will change from network to network. To get it, you can open the network utility
In this case it would be [xmppStream setHostName:#"172.16.1.2"];

Connect iPhone and desktop via HTTP server

How can I get the IP address of an iPhone and access the internal HTTP server?
I want functionality exactly like the CJournal app, to get the backup files in my desktop computer while both it and the iPhone are on the same network, using a dynamically generated link based on the IP address.
This is the screenshot from CJournal app , i made a backup for my contacts list through this app then it generated an url which is clearly shown in the image, in the url 192.168.2.7 is IP address of my iphone in my Wi-Fi network. now please suggest me how to generate this url and how to maintain or access the internal http server through my app
Have you already tried Zeroconf aka Bonjour? This is a DNS Protokol for Service and Device Discovery which is often used in Apple Environments (eg. Airplay) There is also a Windows Framework provided by Apple. On Linux Devices: take a look into Avahi which seems to be the most complete Solution at the Moment. If you need Help on implementation, take a look at the latest WWDC Videos - there have been several Sessions in the last few years.

Resources