使用有限的网络访问测试 iPhone 应用程序

发布于 2024-07-23 10:31:09 字数 53 浏览 7 评论 0原文

使用 iPhone 模拟器时,有什么方法可以模拟有限或无 3G/Wifi/EDGE 连接吗?

Is there any way of simulating limited or no 3G / Wifi / EDGE connectivity when using the iPhone simulator?

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

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

发布评论

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

评论(4

恏ㄋ傷疤忘ㄋ疼 2024-07-30 10:31:09

这是您想要测试的速度变化吗? 或者访问每种技术?

如果是为了速度,那么您可以使用以下 ipfw 技巧(由 Icon Factory 的 Craig Hockenberry 提供)来使用 ipfw 来限制与给定域的连接。 在此示例中,它是 twitter,它限制与主机之间的所有连接的速度。

这是一个 bash 脚本,如果您正在进行 iPhone 开发,您将使用 Mac,因此只需创建它并在终端中运行即可。

#!/bin/bash

# configuration
host="twitter.com"

# usage
if [ "$*" == "" ]; then
    echo "usage: $0 [off|fast|medium|slow]"
    exit
fi

# remove any previous firewall rules
sudo ipfw list 10 > /dev/null 2>&1
if [ $? -eq 0 ]; then
    sudo ipfw delete 10 > /dev/null 2>&1
fi
sudo ipfw list 11 > /dev/null 2>&1
if [ $? -eq 0 ]; then
    sudo ipfw delete 11 > /dev/null 2>&1
fi

# process the command line option
if [ "$1" == "off" ]; then
    # add rules to deny any connections to configured host
    sudo ipfw add 10 deny tcp from $host to me
    sudo ipfw add 11 deny tcp from me to $host
else
    # create a pipe with limited bandwidth
    bandwidth="100Kbit"
    if [ "$1" == "fast" ]; then
        bandwidth="300Kbit"
    elif [ "$1" == "slow" ]; then
        bandwidth="10Kbit"
    fi
    sudo ipfw pipe 1 config bw $bandwidth

    # add rules to use bandwidth limited pipe 
    sudo ipfw add 10 pipe 1 tcp from $host to me
    sudo ipfw add 11 pipe 1 tcp from me to $host
fi

Is it the variations in speed you wish to test? Or access to each technology?

If it's speed then you could use the following ipfw trick, courtesty of Craig Hockenberry of the Icon Factory, to use ipfw to limit connectivity to a given domain. In this example, it's twitter and it limits the speed of all connections to and from the host.

It's a bash script, if you're doing iPhone dev you'll be on a mac so just create it and run in the terminal.

#!/bin/bash

# configuration
host="twitter.com"

# usage
if [ "$*" == "" ]; then
    echo "usage: $0 [off|fast|medium|slow]"
    exit
fi

# remove any previous firewall rules
sudo ipfw list 10 > /dev/null 2>&1
if [ $? -eq 0 ]; then
    sudo ipfw delete 10 > /dev/null 2>&1
fi
sudo ipfw list 11 > /dev/null 2>&1
if [ $? -eq 0 ]; then
    sudo ipfw delete 11 > /dev/null 2>&1
fi

# process the command line option
if [ "$1" == "off" ]; then
    # add rules to deny any connections to configured host
    sudo ipfw add 10 deny tcp from $host to me
    sudo ipfw add 11 deny tcp from me to $host
else
    # create a pipe with limited bandwidth
    bandwidth="100Kbit"
    if [ "$1" == "fast" ]; then
        bandwidth="300Kbit"
    elif [ "$1" == "slow" ]; then
        bandwidth="10Kbit"
    fi
    sudo ipfw pipe 1 config bw $bandwidth

    # add rules to use bandwidth limited pipe 
    sudo ipfw add 10 pipe 1 tcp from $host to me
    sudo ipfw add 11 pipe 1 tcp from me to $host
fi
属性 2024-07-30 10:31:09

您可能想看看 SpeedLimit,这是 OS X 的首选项窗格,可让您限制带宽和控制延迟。

You might want to take a look at SpeedLimit, a Preference Pane for OS X that allows you to throttle bandwidth and control latency.

脸赞 2024-07-30 10:31:09

如果您有 iPhone 网络共享,您可以关闭电缆调制解调器/ASDL 连接,并通过 iPhone 路由互联网。 如果您的运营商是 AT&T,则此方法非常有效。 如果您没有 AT&T 作为运营商,则必须尝试其他方法之一来模拟糟糕的连接。

另一种低保真解决方案是用锡箔包裹您的家庭无线路由器,或将其放入金属盒中。 通常,您想要模拟的是蹩脚的连接,而不是慢速的连接。 防火墙规则会减慢连接速度,但不会丢失随机数据包。

由于您使用的是 Mac,因此可以使用 Dummynet。 它可以插入 ipfw,但也可以模拟数据包丢失。 这是带有 Dummynet 模块的典型 ipfw:

ipfw add 400 prob 0.05 deny sr-ip 10.0.0.0/8

If you have iPhone tethering, you can turn off your cable modem/ASDL connection, and route your internet through your iPhone. This method works really well if your carrier is AT&T. If you don't have AT&T as your carrier, you'll have to try one of the other methods to simulate a crappy connection.

Another lo-fi solution, is to wrap your home wireless router in tin foil, or put it in a metal box. What you want to simulate generally is a crappy connection - not a slow connection. The firewall rules will slow the connection, but won't lose random packets.

Since your on a Mac, you can use Dummynet. This plugs into ipfw, but can also simulate packet loss. Here's a typical ipfw with the Dummynet module:

ipfw add 400 prob 0.05 deny sr-ip 10.0.0.0/8
等你爱我 2024-07-30 10:31:09

您可以通过关闭机场来测试无网络:-)

为了更好地控制,Neil 的 ipfw 建议是最好的方法。

You can test no network by turning your airport off :-)

For finer control, Neil's ipfw suggestion is the best way.

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