147

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?

mfaani
  • 33,269
  • 19
  • 164
  • 293
Chris
  • 5,485
  • 15
  • 68
  • 130
  • Alan's answer should be accepted. – Stanislav Mayorov Jan 29 '19 at 08:46
  • @StanislavMayorov this question is from 9 years ago. Alan then gave an updated answer 4 years later. It is now 5 years after that. Sorry I am not going through and reconsidering accepted answers on my old questions. – Chris Sep 21 '19 at 02:41

7 Answers7

316

How to install Apple’s Network Link Conditioner

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.

Alan H.
  • 16,219
  • 17
  • 80
  • 113
  • 7
    for Xcode 8, this is included in "Additional Tools for Xcode 8" (instead of "Hardware IO Tools for Xcode") – Mohit Singh Sep 26 '16 at 21:52
  • 1
    @MohitSingh Thanks. I have updated the answer above. – Alan H. Oct 10 '16 at 21:47
  • 1
    There seem to be no Additional Tools for Xcode 10.3? – Leo Sep 20 '19 at 13:17
  • 1
    @leo, just use the current Additional Tools for the major version of Xcode you have. For example, use *Additional Tools for Xcode 11* if you have *Xcode 11.1* installed. – Alan H. Oct 25 '19 at 06:00
  • 1
    Or, more accurately, use the latest available Additional Tools, up to the version of Xcode you have. For example, use *Additional Tools for Xcode 11* if you have *Xcode 11.1* installed, since currently there is no version specifically for 11.1. – Alan H. Oct 25 '19 at 06:10
  • 1
    for XCode 13.0 running on macOS Big Sur (11.6) you need to install Additional tools for Xcode 12.5 (instead of Additional tools for Xcode 13). https://developer.apple.com/forums/thread/690358?login=true&page=1#691824022 – Stefan Majiros Oct 19 '21 at 09:51
  • 1
    Network Link Conditioner of Additional Tools for Xcode 13.2 beta works well on Monterey on M1. – Meng-Yuan Huang Nov 24 '21 at 06:55
84

"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)

matm
  • 7,059
  • 5
  • 36
  • 50
  • 2
    Here is a link to browse available downloads : https://developer.apple.com/downloads/index.action – nverinaud Oct 25 '12 at 07:18
  • 2
    doesnt work on Mountain Lion ... http://stackoverflow.com/questions/12414676/network-link-conditioner-seems-to-have-no-effect-on-network-behavior-on-lion-mo – zack Mar 19 '13 at 15:43
  • would be nice if it were app specific, and not for the whole computer – CJT3 Jul 06 '14 at 06:29
  • 3
    You can download "Hardware IO Tools" from Apple's developer tools site now. They update it for new releases of Xcode (and thus OSX): In Xcode, click `Xcode` -> `Open Developer Tool` -> `More Developer Tools...`, login, find the latest archive, download, copy the files somewhere, double click the Network Conditioner preference pane thingy, install it... yay! – i_am_jorf Jul 07 '14 at 19:53
  • I guess doesn't work for Yosemite. I set it to "lossy" but actually didn't get any difference – Injectios Jan 15 '15 at 13:31
  • Thank you so much for this answer! Works fine with Yosemite (10.10.4). – Maria Jul 14 '15 at 12:25
72

An app called SpeedLimit

https://github.com/mschrag/speedlimit

Works great.

chris.

Jeremy Mack
  • 4,987
  • 2
  • 25
  • 22
PyjamaSam
  • 10,437
  • 3
  • 32
  • 20
18

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

mfaani
  • 33,269
  • 19
  • 164
  • 293
1

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 I found to configure the firewall to emulate these parameters:

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


#!/bin/sh
if [ "$#" -ne "3" ]
then
    echo "Usage:\n$0 <bandwidth in kpbs> <delay in ms> <packet loss ratio>";
    exit 1
fi  

BW=$1
DELAY=$2
PLR=$3
sudo ipfw pipe 1 config bw ${BW}Kbit/s delay $DELAY plr $PLR
sudo ipfw add 1 pipe 1 all from me to not me
sudo ipfw add 2 pipe 1 all from not me to me
echo "RETURN to stop connection noise"
read
sudo ipfw delete 1
sudo ipfw delete 2
exit 0

Some suggested values you can use:

Scenario Bw (Kbit) delay (ms) pr (ratio)
2.5G mobile (GPRS) 50 200
3G mobile 1000 200 0.2
VSAT 5000 500 0.2
Busy LAN on VSAT 300 500 0.4
mfaani
  • 33,269
  • 19
  • 164
  • 293
Nick Dowell
  • 2,030
  • 17
  • 17
  • 3
    Network Link Conditioner (tool from Apple that installs as a preference pane) simulates slow connections, packet loss, and latency. – n00neimp0rtant May 02 '14 at 17:40
  • Network Link Conditioner, added in OS X Lion (released in July 2011), makes scripts like this unnecessary. – Nick Dowell May 02 '14 at 17:56
1

You can do it in really device through Xcode(14) settings

Debug -> Induce Device conditions -> Network Link -> select the Network you want

enter image description here

Neha
  • 666
  • 1
  • 10
  • 17
0

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: How to throttle network traffic for environment simulation?

Community
  • 1
  • 1
JJ Rohrer
  • 2,671
  • 5
  • 29
  • 37