iPhone Simulator - 模拟慢速连接?

发布于 2024-08-27 15:37:45 字数 62 浏览 13 评论 0原文

有没有办法减慢 iPhone 模拟器的互联网连接速度,以便模拟当您处于蜂窝网络速度较慢的位置时应用程序的反应?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

清晨说晚安 2024-09-03 15:37:45

如何安装 Apple 的网络链接调节器

这些说明截至 2019 年 10 月。

警告:如果您刚刚升级到新版本的 macOS,请确保安装最新的网络链接调节器< /strong>(Xcode 的其他工具)或者可能 静默失败;也就是说,您将打开它,但它不会限制任何内容或丢弃任何数据包。

更新:从 Xcode 11 开始,可能有一种更简单的方法来模拟联机网络条件设备;请参阅此博文。有关如何影响模拟设备,请像以前一样继续下面的内容。

  1. 如果没有 Xcode,请安装它。

  2. 打开 Xcode 并转至 Xcode › 打开开发者工具 › 更多开发者工具...

按所述导航菜单的屏幕截图

  1. 下载Xcode 的其他工具(与您当前的 Xcode 版本匹配)

其他 IO 工具下载链接< /a>

  1. 打开下载的磁盘映像,然后双击“硬件”下的 Network Link Conditioner .prefpane 进行安装。

首选窗格DMG

显示安装提示的系统偏好设置

  1. 开始吧!

首选项窗格的屏幕截图

  1. 请务必将其打开。您需要选择一个配置文件并启用网络调节器。

在此处输入图像描述

警告

这不会影响本地主机,因此请务必使用临时服务器或同事的计算机模拟与您自己运行的 API 的慢速网络连接。您可能会发现 https://ngrok.com/ 在这方面很有帮助。

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.

狂之美人 2024-09-03 15:37:45

“有一个应用程序可以做到这一点!” ;) Apple 提供的“网络链接调节器”首选项窗格可以很好地完成这项工作。

  • 对于 4.3 之前的 Xcode 版本,安装后,可以在 Developer 文件夹中找到窗格安装程序,例如 "/Developer/Applications/Utilities/Network Link Conditioner",如果守护进程无法启动,并且您不想重新启动计算机,
  • 如果您已经完成了 , 只需使用 sudo launchctl load /system/library/launchdaemons/com.apple.networklinkconditioner.plist Developer 文件夹中,您可以将该窗格作为“Xcode 的硬件 IO 工具”包的一部分进行安装,该包可通过 Mac 开发中心的附加下载部分获取。

下载页面链接(您必须使用您的 Apple ID 登录):https://developer.apple.com/downloads/index .action
(归功于@nverinaud)

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

旧情别恋 2024-09-03 15:37:45

的应用程序

名为 SpeedLimit https://github.com/mschrag/speedlimit

效果很好。

克里斯。

An app called SpeedLimit

https://github.com/mschrag/speedlimit

Works great.

chris.

流年已逝 2024-09-03 15:37:45

还值得一提的是,Xcode 还具有针对设备的内置方式,而不是模拟器。

  • 只需转到“设备和模拟器”(cmmd+shift+2),
  • 选择您的设备,
  • 向下滚动,直到找到“设备条件”,
  • 设置所需的配置文件,
  • 然后点击“开始

在此处输入图像描述

要使其正常工作您需要在 Mac 上安装“网络链接调节器”。请参阅艾伦的回答中提到的步骤

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

煞人兵器 2024-09-03 15:37:45

我认为慢速连接不足以模拟实际工作的移动数据网络行为 - 因为还会有更多的数据包丢失、更高的延迟和更多的连接丢失。

这是我发现的一个方便的脚本,用于配置防火墙以模拟这些参数:

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

您可以使用的一些建议值:

场景Bw (Kbit)延迟(ms)pr (比率)
2.5G 移动(GPRS)50200
3G 移动10002000.2
VSAT50005000.2
VSAT 上 LAN 繁忙3005000.4

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:

ScenarioBw (Kbit)delay (ms)pr (ratio)
2.5G mobile(GPRS)50200
3G mobile10002000.2
VSAT50005000.2
Busy LAN on VSAT3005000.4
友欢 2024-09-03 15:37:45

您可以通过 Xcode(14) 设置

Debug -> 在真实设备中执行此操作诱发设备条件->网络链接->选择您想要的网络

在此处输入图像描述

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

少女情怀诗 2024-09-03 15:37:45

没有直接的方法来模拟慢速连接,这与黑莓开发人员喜欢的良好网络连接模拟器不同。但是,由于模拟器的连接是通过您的计算机进行的 - 您只需专注于减慢计算机的连接速度即可。

您需要实现两件事(取决于您的情况):

  • 限制带宽
  • 增加延迟

也许这将为您指明正确的方向:

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

也有一些很好的开源解决方案,但我记不起它们的名字了。

这个问题可能会有所帮助:如何限制环境模拟的网络流量?

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?

微暖i 2024-09-03 15:37:45

您也可以从 iOS 设备启用网络调节器。
首先启用开发者模式:
设置 ->隐私与隐私安全->开发者模式->将其打开

然后,转到设置 ->开发商->网络链接调节器
并选择一个配置文件来模拟网络状况

You can enable network conditioner from you iOS device as well.
First enable developer mode:
Settings -> Privacy & Security -> Developer Mode -> toggle it on

Then, go to Settings -> Developer -> Network Link Conditioner
and choose a profile to simulate a network condition

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文