iOS Detecting connection speed or type [duplicate]

我的梦境 提交于 2019-11-26 20:16:04

问题


Possible Duplicate:
Iphone detect 3g or wifi

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.


回答1:


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

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.

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

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.



来源:https://stackoverflow.com/questions/10719073/ios-detecting-connection-speed-or-type

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!