测试已测试 | ✗ |
语言语言 | Obj-CObjective C |
许可证 | MIT |
发布日期最新版本 | 2015年3月 |
由Oliver Letterer维护。
AFURLConnectionByteSpeedMeasure
是对 AFNetworking 的扩展,它可以测量 AFURLConnectionOperation
的下载和上传速度并估计完成时间。
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://download.thinkbroadband.com/1GB.zip"]];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
operation.downloadSpeedMeasure.active = YES;
// to avoid a retain cycle one has to pass a weak reference to operation into the progress block.
[operation setDownloadProgressBlock:^(NSUInteger bytesRead, long long totalBytesRead, long long totalBytesExpectedToRead) {
double speedInBytesPerSecond = operation.downloadSpeedMeasure.speed;
NSString *humanReadableSpeed = operation.downloadSpeedMeasure.humanReadableSpeed;
NSTimeInterval remainingTimeInSeconds = [operation.downloadSpeedMeasure remainingTimeOfTotalSize:totalBytesExpectedToRead numberOfCompletedBytes:totalBytesRead];
NSString *humanReadableRemaingTime = [operation.downloadSpeedMeasure humanReadableRemainingTimeOfTotalSize:totalBytesExpectedToRead numberOfCompletedBytes:totalBytesRead];
}];
MIT