- (long long) getContentLength
{
NSURLSessionConfiguration *config = [NSURLSessionConfiguration defaultSessionConfiguration];
NSURLSession *session = [NSURLSession sessionWithConfiguration:config];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:url]];
request.HTTPMethod = @"HEAD";
[request addValue:@"identity" forHTTPHeaderField:@"Accept-Encoding"];
NSURLSessionDownloadTask *uploadTask
= [session downloadTaskWithRequest:request
completionHandler:^(NSURL *url,NSURLResponse *response,NSError *error) {
NSLog(@"handler size: %lld", response.expectedContentLength);
totalContentFileLength = [[NSNumber alloc] initWithFloat:response.expectedContentLength].longLongValue;
}];
NSLog(@"content length=%lld", totalContentFileLength);
[uploadTask resume];
return totalContentFileLength;
}
Я всегда получаю 0
из возвращаемого значения.