Tôi đã googling vô ích, và hy vọng sự giúp đỡ của bạn về điều này.totalBytesExpectedToRead trong setDownloadProgressBlock vẫn còn -1 cho đến khi tải xuống được thực hiện
Tôi đã cố tải xuống hình ảnh bằng cách sử dụng tính năng phát trực tiếp AFHTTPRequestOperation (bằng cách đặt outputstream). Nó tải xuống tệp, không sao cả. Nhưng thanh tiến trình sẽ không hiển thị chính xác, vì totalBytesExpectedToRead luôn trả về -1 và chỉ trả về giá trị chính xác khi tải xuống hoàn tất.
Đây có phải là bản chất của phát trực tuyến không? Hay tôi đã làm điều gì sai?
Mã của tôi bên dưới.
Cảm ơn trước!
(void) invokeAsynchronousSTREAMING: (NSString *) đường dẫn locationToSave: (NSString *) thông số locationToSave: (NSDictionary *) paramDict callId: (NSString *) callId {
NSMutableURLRequest *request = [[AFServerAPIClient sharedClient] requestWithMethod:@"GET"
path:path
parameters:paramDict];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
if(locationToSave!=nil) {
operation.outputStream = [NSOutputStream outputStreamToFileAtPath:locationToSave append:NO];
}
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
//DO SOMETHING
}
failure:^(AFHTTPRequestOperation *operation, NSError *error) {
//DO SOMETHING
}
];
[operation setDownloadProgressBlock:^(NSInteger bytesRead, long long totalBytesRead, long long totalBytesExpectedToRead) {
NSLog(@"invokeAsyncronousSTREAMING - Received %lld of %lld bytes", totalBytesRead, totalBytesExpectedToRead);
//DO SOMETHING
}];
[operation start];
} // end invokeAsyncStreaming