测试具有有限网络访问权限的iPhone应用

Cod*_*eef 7 iphone testing networking

使用iPhone模拟器时,有没有办法模拟有限或无3G/Wifi/EDGE连接?

Nei*_*lis 11

是你想测试的速度变化吗?或访问每种技术?

如果它的速度那么你可以使用以下ipfw技巧,图标工厂的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
Run Code Online (Sandbox Code Playgroud)