iPhone Simulator - Simulate a slow connection?

IphoneNetworkingConnectionIos SimulatorSimulation

Iphone Problem Overview


Is there a way to slow down the internet connection to the iPhone Simulator, so as to mimic how the App might react when you are in a slow spot on the cellular network?

Iphone Solutions


Solution 1 - Iphone

These instructions current as of October 2019.

Warning: If you just upgraded to new version of macOS, make sure you install the very latest Network Conditioner (in Additional Tools for Xcode) or it may silently fail; that is, you will turn it on but it won’t throttle anything or drop any packets.

Update: As of Xcode 11, there may be an even simpler way to simulate network conditions on tethered devices; see this blog post. For how to affect simulated devices, continue below, as before.

  1. Install Xcode if you don’t have it.

  2. Open Xcode and go to Xcode › Open Developer Tool › More Developer Tools…

Screen shot of navigating the menu as described

  1. Download Additional Tools for Xcode (matching your current Xcode version)

Additional IO Tools download link

  1. Open the downloaded disk image and double-click the Network Link Conditioner .prefpane under “Hardware” to install it.

pref pane in DMG

system preferences showing installation prompt

  1. There we go!

Screen shot of the preference pane

  1. Be sure to turn it on. You need to select a profile and enable the network conditioner.

enter image description here

Caveat

This won't affect localhost, so be sure to use a staging server or co-worker's computer to simulate slow network connections to an API you’re running yourself. You may find https://ngrok.com/ helpful in this regard.

Solution 2 - Iphone

"There's an app for that!" ;) Apple provides "Network Link Conditioner" preference pane that does the job quite well.

  • for Xcode versions prior to 4.3, the pane installer can be found in your Developer folder, e.g. "/Developer/Applications/Utilities/Network Link Conditioner", after installation, if daemon fails to start and you don't want to reboot your machine, just use sudo launchctl load /system/library/launchdaemons/com.apple.networklinkconditioner.plist
  • if you are already done with Developer folder, you can install the pane as a part of "Hardware IO Tools for Xcode" package available via Mac Dev Center additional downloads section.

Link to download page (you must log in with your Apple ID): https://developer.apple.com/downloads/index.action
(credits to @nverinaud)

Solution 3 - Iphone

An app called SpeedLimit

https://github.com/mschrag/speedlimit

Works great.

chris.

Solution 4 - Iphone

It also worth mentioning that Xcode also has a built in way for devices, not simulator.

  • Just go 'Devices and Simulator' (cmmd+shift+2)
  • Select your device
  • Scroll down til you find 'Device Conditions'
  • Set your desired profile
  • Hit Start

enter image description here

To have this working you need to install 'Network Link Conditioner' on your Mac. See steps mention in Alan's answer

Solution 5 - Iphone

There isn't a direct way to emulate a slow connection, unlike, say, the nice network connection emulator that blackberry developers enjoy. However, since your simulator's connection goes through your computer - you can simply focus on slowing down your computer's connection.

You'll want to achieve two things (depending upon your circumstances):

  • throttle your bandwidth
  • increase your latency

Maybe this will point you in right direction:

http://www.macosxhints.com/article.php?story=20080119112509736

There are some good open source solutions, too, but I so can't remember their names.

This question might help: https://stackoverflow.com/questions/2273839/how-to-throttle-network-traffic-for-environment-simulation

Solution 6 - Iphone

I would argue that a slow connection isn't enough to simulate real-work mobile data network behaviour - since there is also much more packet loss, higher latencies and more dropped connections too.

Here is a handy script to configure the firewall to emulate these parameters:

http://pmilosev-notes.blogspot.com/2011/02/ios-simulator-testing-over-different.html

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionChrisView Question on Stackoverflow
Solution 1 - IphoneAlan H.View Answer on Stackoverflow
Solution 2 - IphonematmView Answer on Stackoverflow
Solution 3 - IphonePyjamaSamView Answer on Stackoverflow
Solution 4 - IphonemfaaniView Answer on Stackoverflow
Solution 5 - IphoneJJ RohrerView Answer on Stackoverflow
Solution 6 - IphoneNick DowellView Answer on Stackoverflow