진행률 표시 줄을 구성하려고하지만 내 URL이 내 이미지의 전체 크기를 줄 수는 없습니다. totalBytesExpectedToWrite
가 -1 인 경우는 이미지의 전체 크기를 응답하지 않기 때문에 나는, 당신은 당신의 서버 구성에 약간의 문제가,이 튜토리얼을 http://tarikfayad.com/afnetworking-downloading-files-with-progress/Afnetworking 3.0 총 바이트 예상 쓰기 반환 -1
NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:configuration];
//Most URLs I come across are in string format so to convert them into an NSURL and then instantiate the actual request
NSURL *formattedURL = [NSURL URLWithString:@"http://www.wallpapers13.com/wp-content/uploads/2016/04/Sunset-Large-Chinese-wall-Desktop-Wallpaper-HD-5250x3344.jpg"];
NSURLRequest *request = [NSURLRequest requestWithURL:formattedURL];
[manager setDownloadTaskDidWriteDataBlock:^(NSURLSession * _Nonnull session, NSURLSessionDownloadTask * _Nonnull downloadTask, int64_t bytesWritten, int64_t totalBytesWritten, int64_t totalBytesExpectedToWrite) {
//CGFloat w = totalBytesWritten;
CGFloat t = totalBytesExpectedToWrite;
//CGFloat percentageCompleted = w/t;
NSLog(@"%f",t); // Error retun -1
}];
NSURLSessionDownloadTask *download = [manager downloadTaskWithRequest:request progress:nil destination:^NSURL * _Nonnull(NSURL * _Nonnull targetPath, NSURLResponse * _Nonnull response) {
//
//Getting the path of the document directory
NSURL *documentsDirectoryURL = [[NSFileManager defaultManager] URLForDirectory:NSDocumentDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:NO error:nil];
NSURL *fullURL = [documentsDirectoryURL URLByAppendingPathComponent:@"image1.jpg"];
//If we already have a video file saved, remove it from the phone
[self removeVideoAtPath:fullURL];
return fullURL;
} completionHandler:^(NSURLResponse * _Nonnull response, NSURL * _Nullable filePath, NSError * _Nullable error) {
if (!error) {
//If there's no error, return the completion block
[self completionBlock:(NSString *)filePath];
} else {
//Otherwise return the error block
[self errorBlock:error];
}
}];
[download resume];
진행중인 바 시도를 할하려는 경우 :'[작업 setUploadProgressBlock을 ...'여기에 코드 https://gist.github.com/andreortiz82를 차단하는 링크입니다/2934606 – Nazir
이 게시물에 질문이 없습니다. 무엇을 성취하고 싶습니까? 무엇이 도움이 필요합니까? 원래 게시물을 수정하십시오! – ingaham
@ Nazir 서버에서 다운로드하지 않고 업로드하고 싶습니다. 우리가 다운로드 할 때 우리는 얼마나 많은 다운로드 콘텐츠를 알 수 없습니다. 그래서 이걸 도와 줄 수 있어요. –