1

Is there a way to simulate different network conditions on an iOS device programmatically?

iOS provides us with the Network Link Conditioner, but I couldn't find a way to access it programmatically.

If there is no way to manipulate network quality directly, is there a way to simulate it indirectly?

Packet Loss:

  • Could one simulate packet loss by corrupting the data returned by a HTTP request? But would that really simulate packet loss? Wouldn't the request just not return and timeout under heavy packet loss?

Bad Latency:

  • To simulate bad latency, could one just delay HTTP request processing on the client side by a random amount?

Update:

Community
  • 1
  • 1
schmittsfn
  • 1,412
  • 18
  • 40

1 Answers1

0

For my unit tests, I created a small bit of code to do this (under command of the UNIT test). The idea is that wherever you have code that finally dispatches a request to say NSURLConnection, you randomly just don't submit it, and dispatch a "fake" return after some number of seconds with an error of "Timed Out". Likewise, you can instead of immediately dispatching the connection, you put it in a dispatch_after block, and add either a fixed or random delay.

The above is just a handful of code and can be easily implemented. I have mine conditionally compiled (that is, its behind a MACRO that gets defined when for just UNIT Tests).

David H
  • 40,852
  • 12
  • 92
  • 138