我正在调试从Internet获取主数据的应用程序中看到的一些不一致的行为。我在模拟器中没有看到问题,只是在设备上,所以我想在模拟器中重现网络和连接环境。

在模拟器中是否有禁用网络的方法?

(我正在远程连接到Mac上编写代码,目前没有其他选择,所以不能禁用操作系统网络)。


当前回答

一个简单的解决方案是为你的Mac创建一个飞行模式。 以下是如何做到这一点:

go into Network in System Preferences click on Location dropdown menu click on plus icon to add a new location name the new location 'Airplane Mode' or similar, and click 'Done' select the location you just created from the Location dropdown menu click on each available network interface in the list at the left of the window in turn, disabling each one click on the Configure iPv4 menu, and choose Off for Wi-Fi, just click on the Turn Wi-Fi Off button click Apply, and this location will block all network activity

当您想重新启动网络时,只需从“位置”下拉菜单中选择“自动”,然后单击“应用”

此解决方案的信誉:http://hints.macworld.com/article.php?story=20130325002258846

其他回答

自Xcode 4(?)以来,在/Applications/Utilities中有一个名为Network Link Conditioner的首选项窗格。您可以使用现有的配置文件之一,也可以创建自己的自定义配置文件,使用0 kbit/s的up/downlink和100%的drop。

你可以使用第三方应用程序(如Charles)限制互联网连接。

在Mac上点击Command + Shift + T设置节流。

一个简单的解决方案是为你的Mac创建一个飞行模式。 以下是如何做到这一点:

go into Network in System Preferences click on Location dropdown menu click on plus icon to add a new location name the new location 'Airplane Mode' or similar, and click 'Done' select the location you just created from the Location dropdown menu click on each available network interface in the list at the left of the window in turn, disabling each one click on the Configure iPv4 menu, and choose Off for Wi-Fi, just click on the Turn Wi-Fi Off button click Apply, and this location will block all network activity

当您想重新启动网络时,只需从“位置”下拉菜单中选择“自动”,然后单击“应用”

此解决方案的信誉:http://hints.macworld.com/article.php?story=20130325002258846

你可以在你的Mac上使用网络链接调节器。你可以从苹果开发者网站下载它。它应该可以在旧版本的Xcode和iOS中使用。有了这个网络调节器,你可以改变网络的强度,从Wi-Fi到无网络。

此外,当您安装网络调节器时,它会安装在系统首选项中。

如果你的应用程序连接到一个特定的域,你可以简单地将它添加到你的/etc/hosts文件中,并将它路由到本地网络中不存在的IP地址……对于应用程序来说,就像没有任何Internet连接或服务器不可达一样。

sudo nano /etc/hosts

增加如下一行:

192.168.1.123   example.com

如果您在本地机器上没有运行web服务器,则使用127.0.0.1。