How to track a single download speed using asihttprequest

Can someone help me with asihttprequest?

I want to track the download speed of each uploaded file, not the average speed of all files.

There is [ASIHTTPRequest averageBandwidthUsedPerSecond] for the average load of all downloads, but what can I use to track each download?

thanks

+6
source share
2 answers

Given that ASI is dead, I recently had to do this in an older project. If anyone else needs help:

 -(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]; } 
+3
source

You can set downloadProgressDelegate for each request that receives the request: didReceiveBytes: call each time some data is received - you can use this to calculate the download speed.

See here in the documentation:

http://allseeing-i.com/ASIHTTPRequest/How-to-use#custom_progress_tracking

+2
source

Source: https://habr.com/ru/post/890312/


All Articles