Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fake network connection type changes in iOS simulator?

I would like to test my iOS application with all the network conditions possible, including quality of the connection (offline, poor, good) and carrier (WiFi, 3G). For the former, others have already suggested using the Network Link Conditioner, e.g. here:

iPhone simulator - simulate 3G connection

which is just fine for the bandwidth and packet loss, but unfortunately it isn't able to change the carrier type that is reported to the simulator. So I'm looking for a not-so-hacky way of simulating changes in the carrier type. I said not-so-hacky because I have already come up with a hacky solution which, moreover, is incomplete as it can only deceive code which explicitly depends on Apple's famous Reachability module. (Though if anyone is interested, I can post it here.)

Is there a way to hijack/tamper with what the SystemConfiguration API reports?

like image 279
Lvsti Avatar asked Jun 22 '12 10:06

Lvsti


People also ask

How do you simulate poor network conditions on iOS simulator and iPhone?

Simulate Poor Network on iPhoneOpen the Settings app and navigate to the Developer option. Select the Network Link Conditioner under NETWORKING option. Now enable the Network Link Conditioner & choose the network profile you want, and start testing how your app works in different conditions.

How do I simulate a bad Internet connection on my iPhone?

iPhone Device. Go to your Settings and go to Developer menu. Like the Network Link Conditioner in macOS, you can choose a desired profile to simulate for example a poor connection (100% Loss), or a 3G connection and so on.

Is it possible to disable the network in iOS simulator?

Download Hardware IO tools for Xcode. Download and install this tool, then open system preferences in you mac. You'll find the tool Network link conditioner installed there, for newer xcode versions you may find it in Xcode developer tools menu. Use it to control the network.


1 Answers

I use the excellent OHHTTPStubs library to test these things.

You even specify the types of connections you want to mock and their speed. And it's easy to create mock network returns in the tests. Which means you're not testing across an actual network so your tests are more determinate.

like image 171
Abizern Avatar answered Sep 27 '22 03:09

Abizern