有人可以帮助我asihttprequest吗?
我想跟踪下载的每个文件的速度下载,而不是所有文件的平均速度。
对于所有下载的平均spped,有[ASIHTTPRequest averageBandwidthUsedPerSecond]
但我可以用什么来跟踪每次下载?
谢谢
答案 0 :(得分:3)
考虑到ASI已经死了,我最近不得不在一个较旧的项目中这样做。如果有人需要帮助:
-(void)request:(ASIHTTPRequest *)request didReceiveBytes:(long long)bytes
{
if (!lastBytesReceived)
lastBytesReceived = [NSDate date];
NSTimeInterval interval = [[NSDate date] timeIntervalSinceDate:lastBytesReceived];
float KB = (bytes / 1024);
float kbPerSec = KB * (1.0/interval); //KB * (1 second / interval (less than one second))
NSLog(@"%llu bytes received in %f seconds @ %0.01fKB/s",bytes,interval, kbPerSec);
lastBytesReceived = [NSDate date];
}
答案 1 :(得分:2)
您可以为每个请求设置downloadProgressDelegate,它将获得一个请求:didReceiveBytes:每次收到某些数据时调用 - 您可以使用它来计算下载速度。
请参阅文档:
http://allseeing-i.com/ASIHTTPRequest/How-to-use#custom_progress_tracking