Jonathan.
Jonathan.

Reputation: 55544

Fake internet connection on iOS simulator

I'm using Charles Proxy to redirect web requests to a local folder for an app I'm making. However it seems that NSURLConnection checks for an internet connection before attempting to download. How does it perform this check and can I fake the connection being there, because I know it will be able to download the content from the local cache. Or is there a better way of doing this?

EDIT: Actually all I need to do is connect to a fake Wifi hotspot on my laptop, I tried connecting to a BTFON hotspot, which redirects you to a login page for every request until you login (therefore appearing the laptop is connected to the internet, but effectively its not) and it worked when I had Charles proxy enabled. Now I just need to find some software that can connect to Fake Wifi Hotspot, or have a virtual second Wifi adapter, create a adhoc network and connect to that (in a kind of loop)

Upvotes: 2

Views: 6439

Answers (3)

Jonathan.
Jonathan.

Reputation: 55544

Well it seems OSX can do this out the box. The answer is quite simple to make it appear your connected to a WiFi network, just create a adhoc (computer-to-computer) network from the Mac, you don't need to connect any other devices but it means that your computer appears connected to the internet to Laptop and iOS simulator.

So now I can download a copy of the data I need, set up redirects in Charles Proxy (<- amazing software btw) create a adhoc network and still develop my app while I'm not connected to the internet (even though it requires the internet to function)

Upvotes: 4

John Parker
John Parker

Reputation: 54435

You could try simply loading the HTML directly from your application bundle, after creating a URL via the fileURLWithPath: method.

Apple have a Technical Q&A that shows this in operation. (See the first code listing "Loading a document into a UIWebView".)

Upvotes: 0

balexandre
balexandre

Reputation: 75073

as an idea, why don't you use your own web server?

just change the hosts file so you have a full name domain, like: http://mywebserver.local and use that in your connections, you can also provide information using the same technique.

in your program just add a DEBUG clause that would use http://mywebserver.local instead the full path.

Upvotes: 2

Related Questions