iOS检测连接速度或类型 [英] iOS Detecting connection speed or type

查看:104
本文介绍了iOS检测连接速度或类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

Iphone检测3g或wifi

有没有办法获取当前网络速度或设备是否在EDGE / 3G / GPRS?
我可以使用Reachability来区分WiFI和WMAN,但这对我的应用来说还不够。

is there a way to get the current network speed or if the device is on EDGE/3G/GPRS? I can use Reachability to distinguish WiFI from WMAN but that's not enough for my application.

推荐答案

如果你真的需要要知道,你必须测试它。

If you really need to know, you will have to test for it.

建立与低延迟的已知服务器的连接。在单独的线程中,标记时间(时间A)并发送数据包(确保它是一个数据包)。等待那个线程。标记第一个数据包的时间(时间B)。读取数据直到完成。标记最后一个数据包的时间(时间C)。确保服务器响应至少包含三个数据包。

Setup a connection to a known server that has low latency. In a separate thread, mark the time (Time A) and send a packet (make sure it's one packet). Wait on that thread. Mark the time of the first packet (Time B). Read the data until finished. Mark the time of the last packet (Time C). Make sure the server response spans at least three packets.

时间B - 时间A是对延迟的粗略估计。
时间C - 时间B是对带宽的粗略估计。

Time B - Time A is a very rough estimate of latency. Time C - Time B is a very rough estimate of bandwidth.

因为您希望尽可能准确,所以使用您拥有的最低级别的网络访问权限可用(我相信iPhone这是插座)。使用固定长度的随机数据块作为您的请求和响应。请求的几个字节就足够了,但响应需要很好地构建。确保服务器发送一个小的第一个数据包,然后发送一个足够大的数据包序列来填充三个或更多。

Because you want to be accurate as possible, use the lowest level of network access you have available (I believe on the iPhone this is sockets). Use random data blocks of fixed lengths as both your request and response. A few bytes for the request should suffice, but the response needs to be well constructed. Make sure the server sends a small first packet, then a sequence of packets that is large enough to fill three or more.

此时你需要测试。测试,测试,测试和测试。测试不同的网络类型,使用不同的网络流量进行测试,使用交换网络进行测试,并测试您能想到的任何其他内容。

At that point you will need to test. Test, test, test, and test. Test on the different network types, test with different amounts of network traffic, test with switching networks, and test anything else you can think of.

这篇关于iOS检测连接速度或类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆