问题描述
我知道可达性,您可以检查您是否已连接到互联网。但有没有办法确定连接的速度?
我试图分别计算上传速度和下载速度。
I know with reachability you can check if you are connected to the internet. But is there a way to determine the speed of that connection?I am trying to calculate upload speed as well as download speed separately.
如何以编程方式确定互联网上的速度?
How to determine the speed on internet programmatically?
推荐答案
如果你使用 NSURLConnection
来获取一个大文件(比如1 MB或更大),你可以使用以跟踪中间下载进度。
If you use NSURLConnection
to grab a large file (say, 1 MB or greater), you can use a delegate to track intermediate download progress.
具体来说:如果你测量下载的字节数和委托调用之间的时间差,那么你可以计算每秒字节数的持续速度(或其他时间单位)。
Specifically: If you measure the difference in bytes downloaded and the difference in time between calls to the delegate, then you can calculate the ongoing speed in bytes per second (or other time unit).
这篇关于以编程方式确定Internet上的速度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!