【问题标题】:AFNetworking - Check Downloaded bytes before resuming downloading of the file?AFNetworking - 在恢复下载文件之前检查下载的字节?
【发布时间】:2013-06-06 12:56:56
【问题描述】:

我正在使用 AFDownloadRequestOperation 通过AFNetworking Framework 下载文件,每当我在下载时暂停文件然后稍后恢复时,setProgressiveDownloadProgressBlock当文件部分下载时,从零开始返回 totalBytesRead 的值。因此,显示剩余文件调用百分比后的块 setCompletionBlockWithSuccess

但是,我想在进度条中显示正确的进度,那么我应该如何获得下载文件的正确百分比?

【问题讨论】:

    标签: iphone ios objective-c ipad afnetworking


    【解决方案1】:

    这是我用的

     [operation setDownloadProgressBlock:^(NSUInteger bytesRead, long long totalBytesRead, long long totalBytesExpectedToRead) {
                NSLog(@"Operation%i: bytesRead               : %d", i, bytesRead);
                NSLog(@"Operation%i: totalBytesRead          : %lld", i, totalBytesRead);
                NSLog(@"Operation%i: totalBytesExpectedToRead: %lld", i, totalBytesExpectedToRead);
    
                if (totalBytesExpectedToRead > 0)
                {
                     self.progressView.progress = (float)totalBytesRead / totalBytesExpectedToRead;
                }
            }];
    

    引入了检查,因为 totalBytesExpectedToRead 有时会变为 -1,这会破坏 progressview 进度的平滑性 [另请注意,NSUrlconnection 的问题是 hrader 返回 -1 作为预期大小来读取]

    (float)totalBytesRead / totalBytesExpectedToRead * 100 给出百分比

    【讨论】:

    • 请阅读完整的问题..我已经实现了..我在问别的东西..
    猜你喜欢
    • 1970-01-01
    • 2012-09-15
    • 2016-04-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-10
    • 1970-01-01
    相关资源
    最近更新 更多