iPhone Simulator - 模拟慢速连接?
有没有办法减慢 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
如何安装 Apple 的网络链接调节器
这些说明截至 2019 年 10 月。
警告:如果您刚刚升级到新版本的 macOS,请确保安装最新的网络链接调节器< /strong>(Xcode 的其他工具)或者可能 静默失败;也就是说,您将打开它,但它不会限制任何内容或丢弃任何数据包。
更新:从 Xcode 11 开始,可能有一种更简单的方法来模拟联机网络条件设备;请参阅此博文。有关如何影响模拟设备,请像以前一样继续下面的内容。
如果没有 Xcode,请安装它。
打开 Xcode 并转至 Xcode › 打开开发者工具 › 更多开发者工具...
< /a>
警告
这不会影响本地主机,因此请务必使用临时服务器或同事的计算机模拟与您自己运行的 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.
Install Xcode if you don’t have it.
Open Xcode and go to Xcode › Open Developer Tool › More Developer Tools…
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.
“有一个应用程序可以做到这一点!” ;) Apple 提供的“网络链接调节器”首选项窗格可以很好地完成这项工作。
Developer
文件夹中找到窗格安装程序,例如"/Developer/Applications/Utilities/Network Link Conditioner"
,如果守护进程无法启动,并且您不想重新启动计算机,, 只需使用
文件夹中,您可以将该窗格作为“Xcode 的硬件 IO 工具”包的一部分进行安装,该包可通过 Mac 开发中心的附加下载部分获取。sudo launchctl load /system/library/launchdaemons/com.apple.networklinkconditioner.plist
Developer下载页面链接(您必须使用您的 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.
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 usesudo launchctl load /system/library/launchdaemons/com.apple.networklinkconditioner.plist
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)
的应用程序
名为 SpeedLimit https://github.com/mschrag/speedlimit
效果很好。
克里斯。
An app called SpeedLimit
https://github.com/mschrag/speedlimit
Works great.
chris.
还值得一提的是,Xcode 还具有针对设备的内置方式,而不是模拟器。
cmmd+shift+2
),”
要使其正常工作您需要在 Mac 上安装“网络链接调节器”。请参阅艾伦的回答中提到的步骤
It also worth mentioning that Xcode also has a built in way for devices, not simulator.
cmmd+shift+2
)To have this working you need to install 'Network Link Conditioner' on your Mac. See steps mention in Alan's answer
我认为慢速连接不足以模拟实际工作的移动数据网络行为 - 因为还会有更多的数据包丢失、更高的延迟和更多的连接丢失。
这是我发现的一个方便的脚本,用于配置防火墙以模拟这些参数:
http://pmilosev-notes.blogspot.com/2011/02/ios-simulator-testing-over- Different.html
您可以使用的一些建议值:
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
Some suggested values you can use:
您可以通过 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
没有直接的方法来模拟慢速连接,这与黑莓开发人员喜欢的良好网络连接模拟器不同。但是,由于模拟器的连接是通过您的计算机进行的 - 您只需专注于减慢计算机的连接速度即可。
您需要实现两件事(取决于您的情况):
也许这将为您指明正确的方向:
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):
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?
您也可以从 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