是否可以在 iOS 模拟器中禁用网络?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4808433/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Is it possible to disable the network in iOS Simulator?
提问by Paul Hammond
I am trying to debug some inconsistent behaviour I am seeing in an application that gets its primary data from the internet. I don't see the issues in the simulator, just on the device, so I'd like to reproduce the network and connectivity environment in the simulator.
我正在尝试调试我在从 Internet 获取其主要数据的应用程序中看到的一些不一致的行为。我在模拟器中没有看到问题,只是在设备上,所以我想在模拟器中重现网络和连接环境。
Is there any way of disabling the network in the simulator?
有没有办法在模拟器中禁用网络?
(I am connecting to the Mac remotely to code, no other choice right now, so disabling the OS network isn't an option).
(我正在远程连接到 Mac 进行编码,目前没有其他选择,因此禁用操作系统网络不是一种选择)。
采纳答案by Noah Witherspoon
I'm afraid not—the simulator shares whatever network connection the OS is using. I filed a Radar bug reportabout simulating network conditions a while back; you might consider doing the same.
恐怕不会——模拟器共享操作系统正在使用的任何网络连接。不久前,我提交了一份关于模拟网络条件的Radar 错误报告;你可能会考虑做同样的事情。
回答by progrmr
Use a simple Faraday cageto block or limit the external RF signal level.
使用简单的法拉第笼来阻止或限制外部射频信号电平。
You can make your own with aluminum foil. The openings should be smaller than the wavelengthof your data service if that's what you want to block.
你可以用铝箔制作自己的。如果这是您想要阻止的,则开口应小于数据服务的波长。
800 Mhz has a 37 cm (14") wavelength, 1900 Mhz has a 16 cm (6") wavelength.
800 Mhz 的波长为 37 cm (14"),1900 Mhz 的波长为 16 cm (6")。
This works better with an actual device than with the simulator since the Mac is hard to work on when inside the Faraday cage ;-)
这在实际设备上比在模拟器上更有效,因为 Mac 在法拉第笼内很难工作;-)
回答by swathy valluri
Yes. In Xcode, you can go to Xcode
menu item -> Open Developer Tools
-> More Developer Tools
and download "Additional Tools for Xcode", which will have the Network Link Conditioner.
是的。在 Xcode 中,您可以转到Xcode
菜单项 -> Open Developer Tools
->More Developer Tools
并下载“ Additional Tools for Xcode”,其中包含 Network Link Conditioner。
Using this tool, you can simulate different network scenarios (such as 100% loss, 3G, High latency DNS, and more) and you can create your own custom ones as well.
使用此工具,您可以模拟不同的网络场景(例如 100% 丢失、3G、高延迟 DNS 等),您也可以创建自己的自定义场景。
回答by Felix
The only way to disable network on iOS simulator I know is using tools like Little Snitchor Hands Off. With them you can deny/block any out- and ingoing network connections. You can set it up so that it only blocks connections from the simulator app. Works like a firewall.
我知道在 iOS 模拟器上禁用网络的唯一方法是使用Little Snitch或Hands Off等工具。使用它们,您可以拒绝/阻止任何传入和传入网络连接。您可以将其设置为仅阻止来自模拟器应用程序的连接。像防火墙一样工作。
回答by benpalmer
Just turn off your WiFi in Mac OSX this works a treat!
只需在 Mac OSX 中关闭您的 WiFi 即可,这是一种享受!
回答by Nik Kov
Download Additional tools package(Network Link Conditioner)
下载附加工具包(网络链接调节器)
回答by Nik Kov
Just updating the answer to the current date. Since Xcode 4 (?) there is a preferences pane in /Applications/Utilities
called Network Link Conditioner
. Either you use one of the existent profiles or you create your own custom profile with 0 Kbps Up/Downlink and 100% dropped.
只需将答案更新为当前日期。从 Xcode 4 (?) 开始,在/Applications/Utilities
名为Network Link Conditioner
. 您可以使用现有的配置文件之一,也可以使用 0 Kbps 上行/下行链路和 100% 下降创建自己的自定义配置文件。
回答by Ali
Since Xcode does not provide such feature, you will definitely go for some third party application/ tool. Turning off the MAC network will also help to turn off the iOS Simulator network.
由于 Xcode 不提供此类功能,您肯定会选择一些第三方应用程序/工具。关闭 MAC 网络也有助于关闭 iOS Simulator 网络。
You can turn off you MAC internet from "System Preferences...
" > "Network
" and turn off the desire network source.
您可以通过“ System Preferences...
” > “ Network
”关闭您的 MAC 互联网并关闭所需的网络源。
To turnoff you MAC Ethernet internet source:
To turnoff you MAC WiFi internet source(if your MAC is on Wifi Internet):
回答by mabounassif
You can throttle the internet connection with a 3rd party app such as
您可以使用 3rd 方应用程序来限制互联网连接,例如
Charles: http://www.charlesproxy.com/
查尔斯:http: //www.charlesproxy.com/
Hit command + shift + T on a Mac to setup the throttling.
在 Mac 上点击 command + shift + T 来设置节流。
回答by Darshit Shah
One probably crazy idea or patch :
一个可能是疯狂的想法或补丁:
Just toggle the flag of network reachability
只需切换网络可达性标志
This is code which I use to toggle my flag runtime by triggering 'Simulator Memory Warning'and its COMPLETELY SAFE, just make sure code should be in DEBUG Modeonly
这是代码,我用触发切换自己的旗帜运行 “模拟内存警告”和它完全安全的,只要确保代码应该是在DEBUG模式仅
- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application
{
#ifdef DEBUG
isInternetAvailable = !isInternetAvailable;
#endif
}