我使用downloadTaskWithRequest下载一些文件,我使用KVO来观察进程。
这是我的代码:
// create the request from an url
NSMutableURLRequest *request = [mySession.requestSerializer requestWithMethod:@"GET" URLString:url parameters:nil error:&serializationError];
NSProgress *localProgress = nil;
NSURLSessionDownloadTask *downloadTask = [mySession downloadTaskWithRequest:request
progress:localProgress
destination:^NSURL *(NSURL *targetPath, NSURLResponse *response)
{ ... }
completionHandler:^(NSURLResponse *response, NSURL *filePath, NSError *error)
{ ... }];下载文件工作得很好,但是为什么在某些情况下我可以跟踪进度,而对于其他情况,进度从来没有更新过?
进程为ok的url:url = @"http://www.fond-ecran-hd.net/pc-driver/1351.jpg";
没有进展的url:url = @"http://lorempixel.com/1920/1920/";
我知道工作案例和不工作案例之间的区别在于,一些url直接链接到文件(/path/file.ext),而不是其他文件。但我想知道为什么,如果有办法.
发布于 2015-02-02 11:18:19
我从URL获得的HTTP响应对象必须包含一个名为Content的标题,它将给出文件的长度!
如果服务器不返回这一点,似乎不可能跟踪下载进度。
https://stackoverflow.com/questions/28269103
复制相似问题